Java Code Examples for java.util.zip.DataFormatException#getMessage()

The following examples show how to use java.util.zip.DataFormatException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NameValueBlockReader.java    From reader with MIT License 6 votes vote down vote up
public List<String> readNameValueBlock(int length) throws IOException {
  this.compressedLimit += length;
  try {
    int numberOfPairs = nameValueBlockIn.readInt();
    if (numberOfPairs < 0) {
      throw new IOException("numberOfPairs < 0: " + numberOfPairs);
    }
    if (numberOfPairs > 1024) {
      throw new IOException("numberOfPairs > 1024: " + numberOfPairs);
    }
    List<String> entries = new ArrayList<String>(numberOfPairs * 2);
    for (int i = 0; i < numberOfPairs; i++) {
      String name = readString();
      String values = readString();
      if (name.length() == 0) throw new IOException("name.length == 0");
      entries.add(name);
      entries.add(values);
    }

    doneReading();

    return entries;
  } catch (DataFormatException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 2
Source File: NameValueBlockReader.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
public List<String> readNameValueBlock(int length) throws IOException {
  this.compressedLimit += length;
  try {
    int numberOfPairs = nameValueBlockIn.readInt();
    if (numberOfPairs < 0) {
      throw new IOException("numberOfPairs < 0: " + numberOfPairs);
    }
    if (numberOfPairs > 1024) {
      throw new IOException("numberOfPairs > 1024: " + numberOfPairs);
    }
    List<String> entries = new ArrayList<String>(numberOfPairs * 2);
    for (int i = 0; i < numberOfPairs; i++) {
      String name = readString();
      String values = readString();
      if (name.length() == 0) throw new IOException("name.length == 0");
      entries.add(name);
      entries.add(values);
    }

    doneReading();

    return entries;
  } catch (DataFormatException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 3
Source File: CompressWrapper.java    From panama with MIT License 6 votes vote down vote up
@Override
public byte[] unwrap(byte[] bytes) {
    inflater.setInput(bytes);
    try {
        int len;
        byte[] buffer = new byte[bytes.length];
        while (!inflater.finished()) {
            len = inflater.inflate(buffer, 0, buffer.length);
            if (len > 0)
                unwrapBuffer.write(buffer, 0, len);
        }
        return unwrapBuffer.toByteArray();
    } catch (DataFormatException e) {
        throw new RuntimeException("unknown format: " + e.getMessage());
    } finally {
        inflater.reset();
        unwrapBuffer.reset();
    }
}
 
Example 4
Source File: CompressWrapper.java    From AgentX with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] unwrap(byte[] bytes) {
    inflater.setInput(bytes);
    try {
        int len;
        byte[] buffer = new byte[bytes.length];
        while (!inflater.finished()) {
            len = inflater.inflate(buffer, 0, buffer.length);
            if (len > 0)
                unwrapBuffer.write(buffer, 0, len);
        }
        return unwrapBuffer.toByteArray();
    } catch (DataFormatException e) {
        throw new RuntimeException("unknown format: " + e.getMessage());
    } finally {
        inflater.reset();
        unwrapBuffer.reset();
    }
}
 
Example 5
Source File: NameValueBlockReader.java    From wildfly-samples with MIT License 6 votes vote down vote up
public List<String> readNameValueBlock(int length) throws IOException {
  this.compressedLimit += length;
  try {
    int numberOfPairs = nameValueBlockIn.readInt();
    if (numberOfPairs < 0) {
      throw new IOException("numberOfPairs < 0: " + numberOfPairs);
    }
    if (numberOfPairs > 1024) {
      throw new IOException("numberOfPairs > 1024: " + numberOfPairs);
    }
    List<String> entries = new ArrayList<String>(numberOfPairs * 2);
    for (int i = 0; i < numberOfPairs; i++) {
      String name = readString();
      String values = readString();
      if (name.length() == 0) throw new IOException("name.length == 0");
      entries.add(name);
      entries.add(values);
    }

    doneReading();

    return entries;
  } catch (DataFormatException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 6
Source File: NameValueBlockReader.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
public List<String> readNameValueBlock(int length) throws IOException {
  this.compressedLimit += length;
  try {
    int numberOfPairs = nameValueBlockIn.readInt();
    if (numberOfPairs < 0) {
      throw new IOException("numberOfPairs < 0: " + numberOfPairs);
    }
    if (numberOfPairs > 1024) {
      throw new IOException("numberOfPairs > 1024: " + numberOfPairs);
    }
    List<String> entries = new ArrayList<String>(numberOfPairs * 2);
    for (int i = 0; i < numberOfPairs; i++) {
      String name = readString();
      String values = readString();
      if (name.length() == 0) throw new IOException("name.length == 0");
      entries.add(name);
      entries.add(values);
    }

    doneReading();

    return entries;
  } catch (DataFormatException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 7
Source File: NameValueBlockReader.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
public List<String> readNameValueBlock(int length) throws IOException {
  this.compressedLimit += length;
  try {
    int numberOfPairs = nameValueBlockIn.readInt();
    if (numberOfPairs < 0) {
      throw new IOException("numberOfPairs < 0: " + numberOfPairs);
    }
    if (numberOfPairs > 1024) {
      throw new IOException("numberOfPairs > 1024: " + numberOfPairs);
    }
    List<String> entries = new ArrayList<String>(numberOfPairs * 2);
    for (int i = 0; i < numberOfPairs; i++) {
      String name = readString();
      String values = readString();
      if (name.length() == 0) throw new IOException("name.length == 0");
      entries.add(name);
      entries.add(values);
    }

    doneReading();

    return entries;
  } catch (DataFormatException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 8
Source File: NameValueBlockReader.java    From L.TileLayer.Cordova with MIT License 6 votes vote down vote up
public List<String> readNameValueBlock(int length) throws IOException {
  this.compressedLimit += length;
  try {
    int numberOfPairs = nameValueBlockIn.readInt();
    if (numberOfPairs < 0) {
      throw new IOException("numberOfPairs < 0: " + numberOfPairs);
    }
    if (numberOfPairs > 1024) {
      throw new IOException("numberOfPairs > 1024: " + numberOfPairs);
    }
    List<String> entries = new ArrayList<String>(numberOfPairs * 2);
    for (int i = 0; i < numberOfPairs; i++) {
      String name = readString();
      String values = readString();
      if (name.length() == 0) throw new IOException("name.length == 0");
      entries.add(name);
      entries.add(values);
    }

    doneReading();

    return entries;
  } catch (DataFormatException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 9
Source File: NameValueBlockReader.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
public List<String> readNameValueBlock(int length) throws IOException {
  this.compressedLimit += length;
  try {
    int numberOfPairs = nameValueBlockIn.readInt();
    if (numberOfPairs < 0) {
      throw new IOException("numberOfPairs < 0: " + numberOfPairs);
    }
    if (numberOfPairs > 1024) {
      throw new IOException("numberOfPairs > 1024: " + numberOfPairs);
    }
    List<String> entries = new ArrayList<String>(numberOfPairs * 2);
    for (int i = 0; i < numberOfPairs; i++) {
      String name = readString();
      String values = readString();
      if (name.length() == 0) throw new IOException("name.length == 0");
      entries.add(name);
      entries.add(values);
    }

    doneReading();

    return entries;
  } catch (DataFormatException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 10
Source File: InputReader.java    From megan-ce with GNU General Public License v3.0 6 votes vote down vote up
/**
 * reads an archived string
 *
 * @return string
 * @throws java.io.IOException
 * @throws java.util.zip.DataFormatException
 */
public int readString(byte[] tmp, byte[] target) throws IOException {
    int size = readInt();
    if (size > 0) {
        if (size > target.length)
            throw new IOException("Unreasonable string length: " + size);
        return in.read(target, 0, size);
    } else {
        size = -size;
        if (size > tmp.length)
            throw new IOException("Unreasonable string length: " + size);
        int got = in.read(tmp, 0, size);
        if (got != size)
            throw new IOException("Bytes read: " + got + ", expected: " + size);
        try {
            return compressor.inflateByteArray(size, tmp, target);
        } catch (DataFormatException e) {
            throw new IOException(e.getMessage());
        }
    }
}
 
Example 11
Source File: SpdyReader.java    From cordova-android-chromeview with Apache License 2.0 5 votes vote down vote up
private List<String> readNameValueBlock(int length) throws IOException {
  this.compressedLimit += length;
  try {
    int numberOfPairs = nameValueBlockIn.readInt();
    if (numberOfPairs < 0) {
      Logger.getLogger(getClass().getName()).warning("numberOfPairs < 0: " + numberOfPairs);
      throw ioException("numberOfPairs < 0");
    }
    List<String> entries = new ArrayList<String>(numberOfPairs * 2);
    for (int i = 0; i < numberOfPairs; i++) {
      String name = readString();
      String values = readString();
      if (name.length() == 0) throw ioException("name.length == 0");
      if (values.length() == 0) throw ioException("values.length == 0");
      entries.add(name);
      entries.add(values);
    }

    if (compressedLimit != 0) {
      Logger.getLogger(getClass().getName()).warning("compressedLimit > 0: " + compressedLimit);
    }

    return entries;
  } catch (DataFormatException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 12
Source File: RpcInflaterOutputStream.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
/**
 * Flushes this output stream, forcing any pending buffered output bytes to be
 * written.
 *
 * @throws IOException if an I/O error occurs or this stream is already
 * closed
 */
public void flush() throws IOException {
    ensureOpen();

    // Finish decompressing and writing pending output data
    if (!inf.finished()) {
        try {
            while (!inf.finished()  &&  !inf.needsInput()) {
                int n;

                // Decompress pending output data
                n = inf.inflate(buf, 0, buf.length);
                if (n < 1) {
                    break;
                }

                // Write the uncompressed output data block
                out.write(buf, 0, n);
                updateDigest(buf, 0, n);
            }
            super.flush();
        } catch (DataFormatException ex) {
            // Improperly formatted compressed (ZIP) data
            String msg = ex.getMessage();
            if (msg == null) {
                msg = "Invalid ZLIB data format";
            }
            throw new ZipException(msg);
        }
    }
}
 
Example 13
Source File: OpenJDK7InflaterInputStream.java    From webarchive-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Reads uncompressed data into an array of bytes. If <code>len</code> is not
 * zero, the method will block until some input can be decompressed; otherwise,
 * no bytes are read and <code>0</code> is returned.
 * @param b the buffer into which the data is read
 * @param off the start offset in the destination array <code>b</code>
 * @param len the maximum number of bytes read
 * @return the actual number of bytes read, or -1 if the end of the
 *         compressed input is reached or a preset dictionary is needed
 * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 * <code>len</code> is negative, or <code>len</code> is greater than
 * <code>b.length - off</code>
 * @exception ZipException if a ZIP format error has occurred
 * @exception IOException if an I/O error has occurred
 */
public int read(byte[] b, int off, int len) throws IOException {
    ensureOpen();
    if (b == null) {
        throw new NullPointerException();
    } else if (off < 0 || len < 0 || len > b.length - off) {
        throw new IndexOutOfBoundsException();
    } else if (len == 0) {
        return 0;
    }
    try {
        int n;
        while ((n = inf.inflate(b, off, len)) == 0) {
            if (inf.finished() || inf.needsDictionary()) {
                reachEOF = true;
                return -1;
            }
            if (inf.needsInput()) {
                fill();
            }
        }
        return n;
    } catch (DataFormatException e) {
        String s = e.getMessage();
        throw new ZipException(s != null ? s : "Invalid ZLIB data format");
    }
}
 
Example 14
Source File: RpcInflaterOutputStream.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
/**
 * Flushes this output stream, forcing any pending buffered output bytes to be
 * written.
 *
 * @throws IOException if an I/O error occurs or this stream is already
 * closed
 */
public void flush() throws IOException {
    ensureOpen();

    // Finish decompressing and writing pending output data
    if (!inf.finished()) {
        try {
            while (!inf.finished()  &&  !inf.needsInput()) {
                int n;

                // Decompress pending output data
                n = inf.inflate(buf, 0, buf.length);
                if (n < 1) {
                    break;
                }

                // Write the uncompressed output data block
                out.write(buf, 0, n);
                updateDigest(buf, 0, n);
            }
            super.flush();
        } catch (DataFormatException ex) {
            // Improperly formatted compressed (ZIP) data
            String msg = ex.getMessage();
            if (msg == null) {
                msg = "Invalid ZLIB data format";
            }
            throw new ZipException(msg);
        }
    }
}
 
Example 15
Source File: BuiltInZlibInflater.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized int decompress(byte[] b, int off, int len) 
  throws IOException {
  try {
    return super.inflate(b, off, len);
  } catch (DataFormatException dfe) {
    throw new IOException(dfe.getMessage());
  }
}
 
Example 16
Source File: GzipInflatingBuffer.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
private int inflate(byte[] b, int off, int len) throws DataFormatException, ZipException {
  checkState(inflater != null, "inflater is null");

  try {
    int inflaterTotalIn = inflater.getTotalIn();
    int n = inflater.inflate(b, off, len);
    int bytesConsumedDelta = inflater.getTotalIn() - inflaterTotalIn;
    bytesConsumed += bytesConsumedDelta;
    deflatedBytesConsumed += bytesConsumedDelta;
    inflaterInputStart += bytesConsumedDelta;
    crc.update(b, off, n);

    if (inflater.finished()) {
      // Save bytes written to check against the trailer ISIZE
      expectedGzipTrailerIsize = (inflater.getBytesWritten() & 0xffffffffL);

      state = State.TRAILER;
    } else if (inflater.needsInput()) {
      state = State.INFLATER_NEEDS_INPUT;
    }

    return n;
  } catch (DataFormatException e) {
    // Wrap the exception so tests can check for a specific prefix
    throw new DataFormatException("Inflater data format exception: " + e.getMessage());
  }
}
 
Example 17
Source File: RpcInflaterOutputStream.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
/**
 * Flushes this output stream, forcing any pending buffered output bytes to be
 * written.
 *
 * @throws IOException if an I/O error occurs or this stream is already
 * closed
 */
public void flush() throws IOException {
    ensureOpen();

    // Finish decompressing and writing pending output data
    if (!inf.finished()) {
        try {
            while (!inf.finished()  &&  !inf.needsInput()) {
                int n;

                // Decompress pending output data
                n = inf.inflate(buf, 0, buf.length);
                if (n < 1) {
                    break;
                }

                // Write the uncompressed output data block
                out.write(buf, 0, n);
                updateDigest(buf, 0, n);
            }
            super.flush();
        } catch (DataFormatException ex) {
            // Improperly formatted compressed (ZIP) data
            String msg = ex.getMessage();
            if (msg == null) {
                msg = "Invalid ZLIB data format";
            }
            throw new ZipException(msg);
        }
    }
}
 
Example 18
Source File: RpcInflaterOutputStream.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
/**
 * Flushes this output stream, forcing any pending buffered output bytes to be
 * written.
 *
 * @throws IOException if an I/O error occurs or this stream is already
 * closed
 */
public void flush() throws IOException {
    ensureOpen();

    // Finish decompressing and writing pending output data
    if (!inf.finished()) {
        try {
            while (!inf.finished()  &&  !inf.needsInput()) {
                int n;

                // Decompress pending output data
                n = inf.inflate(buf, 0, buf.length);
                if (n < 1) {
                    break;
                }

                // Write the uncompressed output data block
                out.write(buf, 0, n);
                updateDigest(buf, 0, n);
            }
            super.flush();
        } catch (DataFormatException ex) {
            // Improperly formatted compressed (ZIP) data
            String msg = ex.getMessage();
            if (msg == null) {
                msg = "Invalid ZLIB data format";
            }
            throw new ZipException(msg);
        }
    }
}
 
Example 19
Source File: CompressedBlockInputStream.java    From blucat with GNU General Public License v2.0 4 votes vote down vote up
private void readAndDecompress() throws IOException {
    // Read the length of the compressed block
    int ch1 = in.read();
    int ch2 = in.read();
    int ch3 = in.read();
    int ch4 = in.read();
    if ((ch1 | ch2 | ch3 | ch4) < 0)
        throw new EOFException();
    inLength = ((ch1 << 24) + (ch2 << 16) + 
        (ch3 << 8) + (ch4 << 0));

    ch1 = in.read();
    ch2 = in.read();
    ch3 = in.read();
    ch4 = in.read();
    if ((ch1 | ch2 | ch3 | ch4) < 0)
        throw new EOFException();
    outLength = ((ch1 << 24) + (ch2 << 16) + 
        (ch3 << 8) + (ch4 << 0));

    // Make sure we've got enough space to read the block
    if ((inBuf == null) || (inLength > inBuf.length)) {
        inBuf = new byte[inLength];
    }

    if ((outBuf == null) || (outLength > outBuf.length)) {
        outBuf = new byte[outLength];
    }

    // Read until we're got the entire compressed buffer. 
    // read(...) will not necessarily block until all 
    // requested data has been read, so we loop until 
    // we're done.
    int inOffs = 0;
    while (inOffs < inLength) {
        int inCount = 
            in.read(inBuf, inOffs, inLength - inOffs);
        if (inCount == -1) {
            throw new EOFException();
        }
        inOffs += inCount;
    }

    inflater.setInput(inBuf, 0, inLength);
    try {
        inflater.inflate(outBuf);
    }
    catch(DataFormatException dfe) {
        throw new IOException(
            "Data format exception - " + 
            dfe.getMessage());
    }

    // Reset the inflator so we can re-use it for the 
    // next block
    inflater.reset();

    outOffs = 0;
}
 
Example 20
Source File: InflaterInputStream.java    From AndroidZip with Apache License 2.0 4 votes vote down vote up
public int read(byte[] b, int off, int len) throws IOException {
	
	if (b == null) {
		throw new NullPointerException("input buffer is null");
	} else if (off < 0 || len < 0 || len > b.length - off) {
	    throw new IndexOutOfBoundsException();
	} else if (len == 0) {
	    return 0;
	}
	
	try {
	    int n;
	    if (bytesWritten >= uncompressedSize) {
	    	finishInflating();
	    	return -1;
	    }
	    while ((n = inflater.inflate(b, off, len)) == 0) {
			if (inflater.finished() || inflater.needsDictionary()) {
				finishInflating();
			    return -1;
			}
			if (inflater.needsInput()) {
				fill();
			}
	    }
	    bytesWritten += n;
	    return n;
	} catch (DataFormatException e) {
	    String s = "Invalid ZLIB data format";
	    if (e.getMessage() != null) {
	    	s = e.getMessage();
	    }
	    if (unzipEngine != null) {
	    	if (unzipEngine.getLocalFileHeader().isEncrypted() && 
	    			unzipEngine.getLocalFileHeader().getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) {
	    		s += " - Wrong Password?";
	    	}
	    }
	    throw new IOException(s);
	}
}