@Override public void expand(byte[] in, int inPos, int inLen, byte[] out, int outPos, int outLen) { Inflater decompresser = new Inflater(); decompresser.setInput(in, inPos, inLen); decompresser.finished(); try { int len = decompresser.inflate(out, outPos, outLen); if (len != outLen) { throw new DataFormatException(len + " " + outLen); } } catch (DataFormatException e) { throw DbException.get(ErrorCode.COMPRESSION_ERROR, e); } decompresser.end(); }
public void expand(byte[] in, int inPos, int inLen, byte[] out, int outPos, int outLen) { Inflater decompresser = new Inflater(); decompresser.setInput(in, inPos, inLen); decompresser.finished(); try { int len = decompresser.inflate(out, outPos, outLen); if (len != outLen) { throw new DataFormatException(len + " " + outLen); } } catch (DataFormatException e) { throw DbException.get(ErrorCode.COMPRESSION_ERROR, e); } decompresser.end(); }
throw new DataFormatException("Input is over while inflater still expecting data"); } else { throw new DataFormatException("Inflater is neither finished nor needing input.");
/** * Inflates up to {@code byteCount} bytes from the current input and stores them in * {@code buf} starting at {@code offset}. * * @throws DataFormatException * if the underlying stream is corrupted or was not compressed * using a {@code Deflater}. * @return the number of bytes inflated. */ public synchronized int inflate(byte[] buf, int offset, int byteCount) throws DataFormatException { Arrays.checkOffsetAndCount(buf.length, offset, byteCount); checkOpen(); if (needsInput()) { return 0; } boolean neededDict = needsDictionary; needsDictionary = false; int result = inflateImpl(buf, offset, byteCount, streamHandle); if (needsDictionary && neededDict) { throw new DataFormatException("Needs dictionary"); } return result; }
int setInput(long pos, Inflater inf) throws DataFormatException { int ptr = (int) (pos - start); int cnt = block.length - ptr; if (cnt <= 0) { throw new DataFormatException(cnt + " bytes to inflate:" //$NON-NLS-1$ + " at pos=" + pos //$NON-NLS-1$ + "; block.start=" + start //$NON-NLS-1$ + "; ptr=" + ptr //$NON-NLS-1$ + "; block.length=" + block.length); //$NON-NLS-1$ } inf.setInput(block, ptr, cnt); return cnt; }
protected JSONObject handleBinary(byte[] binary) throws DataFormatException, UnsupportedEncodingException { //Thanks to ShadowLordAlpha and Shredder121 for code and debugging. //Get the compressed message and inflate it //We use the same buffer here to optimize gc use ByteArrayOutputStream decompressBuffer = getDecompressBuffer(); try (InflaterOutputStream decompressor = new InflaterOutputStream(decompressBuffer, zlibContext)) { if (readBuffer != null) readBuffer.writeTo(decompressor); else decompressor.write(binary); } catch (IOException e) { decompressBuffer.reset(); throw (DataFormatException) new DataFormatException("Malformed").initCause(e); } finally { readBuffer = null; } String jsonString = decompressBuffer.toString("UTF-8"); decompressBuffer.reset(); return new JSONObject(jsonString); }
byte[] inflate(long filePos, int len) throws IOException, DataFormatException { byte[] dstbuf; try { dstbuf = new byte[len]; } catch (OutOfMemoryError noMemory) { return null; // Caller will switch to large object streaming. } byte[] srcbuf = buffer(); Inflater inf = inflater(); filePos += setInput(filePos, inf, srcbuf); for (int dstoff = 0;;) { int n = inf.inflate(dstbuf, dstoff, dstbuf.length - dstoff); dstoff += n; if (inf.finished()) { return dstbuf; } if (inf.needsInput()) { filePos += setInput(filePos, inf, srcbuf); } else if (n == 0) { throw new DataFormatException(); } } }
byte[] inflate(DfsReader ctx, long pos, int len) throws IOException, DataFormatException { byte[] dstbuf; try { dstbuf = new byte[len]; } catch (OutOfMemoryError noMemory) { return null; // Caller will switch to large object streaming. } Inflater inf = ctx.inflater(); pos += setInput(pos, inf); for (int dstoff = 0;;) { int n = inf.inflate(dstbuf, dstoff, dstbuf.length - dstoff); dstoff += n; if (inf.finished()) return dstbuf; if (inf.needsInput()) pos += setInput(pos, inf); else if (n == 0) throw new DataFormatException(); } }
position += window.setInput(position, inf); } else if (n == 0) throw new DataFormatException();
position += block.setInput(position, inf); } else if (n == 0) throw new DataFormatException();
void set(String data[]) throws DataFormatException { try { a = Integer.parseInt(data[0]);// convert the string into int. // eg1.("12" // ---> 12) eg2.("df23" ---> fail) b = Integer.parseInt(data[1]); c = 0; } catch (NumberFormatException e) { throw new DataFormatException(e); } catch (ArrayIndexOutOfBoundsException e) { throw new DataFormatException(e); } }
int setInput(long pos, Inflater inf) throws DataFormatException { int ptr = (int) (pos - start); int cnt = block.length - ptr; if (cnt <= 0) { throw new DataFormatException(cnt + " bytes to inflate:" //$NON-NLS-1$ + " at pos=" + pos //$NON-NLS-1$ + "; block.start=" + start //$NON-NLS-1$ + "; ptr=" + ptr //$NON-NLS-1$ + "; block.length=" + block.length); //$NON-NLS-1$ } inf.setInput(block, ptr, cnt); return cnt; }
int setInput(long pos, Inflater inf) throws DataFormatException { int ptr = (int) (pos - start); int cnt = block.length - ptr; if (cnt <= 0) { throw new DataFormatException(cnt + " bytes to inflate:" //$NON-NLS-1$ + " at pos=" + pos //$NON-NLS-1$ + "; block.start=" + start //$NON-NLS-1$ + "; ptr=" + ptr //$NON-NLS-1$ + "; block.length=" + block.length); //$NON-NLS-1$ } inf.setInput(block, ptr, cnt); return cnt; }
private void verifyCrc() throws DataFormatException { long crcValue = 0; for (int i = 0; i < 4; ++i) { crcValue |= (long) readUnsignedByte() << i * 8; } long readCrc = crc.getValue(); if (crcValue != readCrc) { throw new DataFormatException( "CRC value missmatch. Expected: " + crcValue + ", Got: " + readCrc); } }
/** {@inheritDoc} */ @Override public void read(final URL url) throws IOException, DataFormatException { final URLConnection connection = url.openConnection(); if (!connection.getContentType().equals("image/bmp")) { throw new DataFormatException(BAD_FORMAT); } final int length = connection.getContentLength(); if (length < 0) { throw new FileNotFoundException(url.getFile()); } read(url.openStream()); }
/** {@inheritDoc} */ @Override public void read(final URL url) throws IOException, DataFormatException { final URLConnection connection = url.openConnection(); if (!connection.getContentType().equals("image/bmp")) { throw new DataFormatException(BAD_FORMAT); } final int length = connection.getContentLength(); if (length < 0) { throw new FileNotFoundException(url.getFile()); } read(url.openStream()); }
private void checkTrailer(ByteBuffer in) throws DataFormatException { GZipHeader.Trailer trailer = GZipHeader.readGZipTrailer(in); if (trailer.getLength() != inflater.getBytesWritten()) { throw new DataFormatException("GZip length does not match"); } if (trailer.getChecksum() != checksum.getValue()) { throw new DataFormatException("GZip checksum does not match"); } }
/** {@inheritDoc} */ @Override public void read(final File file) throws IOException, DataFormatException { final ImageInfo info = new ImageInfo(); info.setInput(new RandomAccessFile(file, "r")); // info.setDetermineImageNumber(true); if (!info.check()) { throw new DataFormatException(BAD_FORMAT); } read(new FileInputStream(file)); }
/** {@inheritDoc} */ @Override public void read(final File file) throws IOException, DataFormatException { final ImageInfo info = new ImageInfo(); info.setInput(new RandomAccessFile(file, "r")); // info.setDetermineImageNumber(true); if (!info.check()) { throw new DataFormatException(BAD_FORMAT); } read(new FileInputStream(file)); }
public static Trailer readGZipTrailer(ByteBuffer buf) throws DataFormatException { if (buf.remaining() < TRAILER_SIZE) { throw new DataFormatException("No GZIP trailer"); } Trailer t = new Trailer(); t.setChecksum(readUInt32LE(buf)); t.setLength(readUInt32LE(buf)); return t; }