Java Code Examples for java.util.zip.DataFormatException

The following are top voted examples for showing how to use java.util.zip.DataFormatException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: trashjam2017   File: PNGDecoder.java   View source code 6 votes vote down vote up
private void readChunkUnzip(Inflater inflater, byte[] buffer, int offset, int length) throws IOException {
    try {
        do {
            int read = inflater.inflate(buffer, offset, length);
            if(read <= 0) {
                if(inflater.finished()) {
                    throw new EOFException();
                }
                if(inflater.needsInput()) {
                    refillInflater(inflater);
                } else {
                    throw new IOException("Can't inflate " + length + " bytes");
                }
            } else {
                offset += read;
                length -= read;
            }
        } while(length > 0);
    } catch (DataFormatException ex) {
        throw (IOException)(new IOException("inflate error").initCause(ex));
    }
}
 
Example 2
Project: HeroVideo-master   File: BiliDanmukuCompressionTools.java   View source code 6 votes vote down vote up
public static byte[] decompress(byte[] value) throws DataFormatException
{

    ByteArrayOutputStream bos = new ByteArrayOutputStream(value.length);

    Inflater decompressor = new Inflater();

    try
    {
        decompressor.setInput(value);

        final byte[] buf = new byte[1024];
        while (!decompressor.finished())
        {
            int count = decompressor.inflate(buf);
            bos.write(buf, 0, count);
        }
    } finally
    {
        decompressor.end();
    }

    return bos.toByteArray();
}
 
Example 3
Project: sstable-adaptor   File: DeflateCompressor.java   View source code 6 votes vote down vote up
public int uncompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) throws IOException
{
    Inflater inf = inflater.get();
    inf.reset();
    inf.setInput(input, inputOffset, inputLength);
    if (inf.needsInput())
        return 0;

    // We assume output is big enough
    try
    {
        return inf.inflate(output, outputOffset, maxOutputLength);
    }
    catch (DataFormatException e)
    {
        throw new IOException(e);
    }
}
 
Example 4
Project: litiengine   File: CompressionUtilities.java   View source code 6 votes vote down vote up
public static byte[] decompress(final byte[] data) {
  final Inflater inflater = new Inflater();
  inflater.setInput(data);
  final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
  final byte[] buffer = new byte[1024];
  try {
    while (!inflater.finished()) {
      int count;

      count = inflater.inflate(buffer);

      outputStream.write(buffer, 0, count);
    }

    outputStream.close();
  } catch (final DataFormatException | IOException e) {
    log.log(Level.SEVERE, e.getMessage(), e);
  }

  return outputStream.toByteArray();
}
 
Example 5
Project: BedrockProxy   File: BatchPacket.java   View source code 6 votes vote down vote up
@Override
public void decode() {
    if (buffer().readableBytes() < 2) return;

    try {
        setBuffer(Compression.inflate(buffer()));
    } catch (DataFormatException e) {
        e.printStackTrace();
        return;
    }

    if (buffer().readableBytes() == 0) {
        throw new RuntimeException("Decoded BatchPacket payload is empty");
    }

    buffer().readerIndex(2);
    while (buffer().readerIndex() < buffer().readableBytes()) {
        PacketRegistry.handlePacket(new RakNetPacket(readBytes()), getPlayer());
    }
}
 
Example 6
Project: FApkSigner   File: LocalFileRecord.java   View source code 6 votes vote down vote up
@Override
public void consume(byte[] buf, int offset, int length) throws IOException {
    checkNotClosed();
    mInflater.setInput(buf, offset, length);
    if (mOutputBuffer == null) {
        mOutputBuffer = new byte[65536];
    }
    while (!mInflater.finished()) {
        int outputChunkSize;
        try {
            outputChunkSize = mInflater.inflate(mOutputBuffer);
        } catch (DataFormatException e) {
            throw new IOException("Failed to inflate data", e);
        }
        if (outputChunkSize == 0) {
            return;
        }
        mDelegate.consume(mOutputBuffer, 0, outputChunkSize);
        mOutputByteCount += outputChunkSize;
    }
}
 
Example 7
Project: AgentX   File: CompressWrapper.java   View source code 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 8
Project: NotiCap   File: FilterRule.java   View source code 6 votes vote down vote up
public static JSONObject loadSavedFilterRules(Context context, boolean overwrite) throws IOException, DataFormatException, JSONException {
	File file = context.getFileStreamPath("rules");
	if (!file.exists())
		//noinspection ResultOfMethodCallIgnored
		file.createNewFile();

	byte[] content = Compressor.readFile(file);

	if (!overwrite && content.length > 0) {
		String data = new String(Compressor.decompress(content), "UTF-8");
		return new JSONObject(data);
	} else
		return new JSONObject().put("rules", new JSONArray());
}
 
Example 9
Project: NotiCap   File: SSHIdentity.java   View source code 6 votes vote down vote up
public static JSONObject loadSavedIdentities(Context context, boolean overwrite) throws IOException, DataFormatException, JSONException {
	File file = context.getFileStreamPath("identities");
	if (!file.exists())
		//noinspection ResultOfMethodCallIgnored
		file.createNewFile();

	byte[] content = Compressor.readFile(file);

	if (!overwrite && content.length > 0) {
		String data = new String(Compressor.decompress(content), "UTF-8");
		return new JSONObject(data);
	} else
		return new JSONObject().put("identities", new JSONArray());
}
 
Example 10
Project: NotiCap   File: SSHIdentity.java   View source code 6 votes vote down vote up
public static SSHIdentity fromID(Context context, long id) throws JSONException, IOException, DataFormatException {
	JSONArray savedIdentities = SSHIdentity.loadSavedIdentities(context, false).getJSONArray("identities");
	for (int i = 0; i < savedIdentities.length(); i++) {
		JSONObject identityObj = savedIdentities.getJSONObject(i);
		if (identityObj == null)
			continue;
		if (identityObj.getLong("id") == id) {
			return new SSHIdentity(
					identityObj.getString("name"),
					identityObj.getString("host"),
					identityObj.getString("username"),
					identityObj.optString("password"),
					identityObj.optString("keyFilePath"),
					identityObj.optString("keyFilePassword"),
					identityObj.getInt("port"),
					identityObj.getLong("id")
			);
		}
	}
	return new SSHIdentity();
}
 
Example 11
Project: cas-5.1.0   File: CompressionUtils.java   View source code 6 votes vote down vote up
/**
 * Inflate the given byte array by {@link #INFLATED_ARRAY_LENGTH}.
 *
 * @param bytes the bytes
 * @return the array as a string with {@code UTF-8} encoding
 */
public static String inflate(final byte[] bytes) {
    final Inflater inflater = new Inflater(true);
    final byte[] xmlMessageBytes = new byte[INFLATED_ARRAY_LENGTH];

    final byte[] extendedBytes = new byte[bytes.length + 1];
    System.arraycopy(bytes, 0, extendedBytes, 0, bytes.length);
    extendedBytes[bytes.length] = 0;

    inflater.setInput(extendedBytes);

    try {
        final int resultLength = inflater.inflate(xmlMessageBytes);
        inflater.end();

        if (!inflater.finished()) {
            throw new RuntimeException("buffer not large enough.");
        }

        inflater.end();
        return new String(xmlMessageBytes, 0, resultLength, StandardCharsets.UTF_8);
    } catch (final DataFormatException e) {
        return null;
    }
}
 
Example 12
Project: Android-UtilCode   File: LogUtils.java   View source code 6 votes vote down vote up
public static byte[] uncompress(byte[] input) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Inflater decompressor = new Inflater();
    try {
        decompressor.setInput(input);
        final byte[] buf = new byte[2048];
        while (!decompressor.finished()) {
            int count = 0;
            try {
                count = decompressor.inflate(buf);
            } catch (DataFormatException e) {
                e.printStackTrace();
            }
            bos.write(buf, 0, count);
        }
    } finally {
        decompressor.end();
    }
    return bos.toByteArray();
}
 
Example 13
Project: Progetto-C   File: PNGDecoder.java   View source code 6 votes vote down vote up
private void readChunkUnzip(Inflater inflater, byte[] buffer, int offset, int length) throws IOException {
    try {
        do {
            int read = inflater.inflate(buffer, offset, length);
            if(read <= 0) {
                if(inflater.finished()) {
                    throw new EOFException();
                }
                if(inflater.needsInput()) {
                    refillInflater(inflater);
                } else {
                    throw new IOException("Can't inflate " + length + " bytes");
                }
            } else {
                offset += read;
                length -= read;
            }
        } while(length > 0);
    } catch (DataFormatException ex) {
        throw (IOException)(new IOException("inflate error").initCause(ex));
    }
}
 
Example 14
Project: elasticsearch_my   File: AbstractInternalHDRPercentiles.java   View source code 6 votes vote down vote up
/**
 * Read from a stream.
 */
protected AbstractInternalHDRPercentiles(StreamInput in) throws IOException {
    super(in);
    format = in.readNamedWriteable(DocValueFormat.class);
    keys = in.readDoubleArray();
    long minBarForHighestToLowestValueRatio = in.readLong();
    final int serializedLen = in.readVInt();
    byte[] bytes = new byte[serializedLen];
    in.readBytes(bytes, 0, serializedLen);
    ByteBuffer stateBuffer = ByteBuffer.wrap(bytes);
    try {
        state = DoubleHistogram.decodeFromCompressedByteBuffer(stateBuffer, minBarForHighestToLowestValueRatio);
    } catch (DataFormatException e) {
        throw new IOException("Failed to decode DoubleHistogram for aggregation [" + name + "]", e);
    }
    keyed = in.readBoolean();
}
 
Example 15
Project: BilibiliClient   File: BiliDanmukuCompressionTools.java   View source code 6 votes vote down vote up
public static byte[] decompress(byte[] value) throws DataFormatException {

    ByteArrayOutputStream bos = new ByteArrayOutputStream(value.length);

    Inflater decompressor = new Inflater();

    try {
      decompressor.setInput(value);

      final byte[] buf = new byte[1024];
      while (!decompressor.finished()) {
        int count = decompressor.inflate(buf);
        bos.write(buf, 0, count);
      }
    } finally {
      decompressor.end();
    }

    return bos.toByteArray();
  }
 
Example 16
Project: BilibiliClient   File: BiliDanmukuCompressionTools.java   View source code 6 votes vote down vote up
public static byte[] decompress(byte[] value) throws DataFormatException {

    ByteArrayOutputStream bos = new ByteArrayOutputStream(value.length);

    Inflater decompressor = new Inflater();

    try {
      decompressor.setInput(value);

      final byte[] buf = new byte[1024];
      while (!decompressor.finished()) {
        int count = decompressor.inflate(buf);
        bos.write(buf, 0, count);
      }
    } finally {
      decompressor.end();
    }

    return bos.toByteArray();
  }
 
Example 17
Project: odb-artax   File: PNGDecoder.java   View source code 6 votes vote down vote up
private void readChunkUnzip(Inflater inflater, byte[] buffer, int offset, int length) throws IOException {
    assert(buffer != this.buffer);
    try {
        do {
            int read = inflater.inflate(buffer, offset, length);
            if(read <= 0) {
                if(inflater.finished()) {
                    throw new EOFException();
                }
                if(inflater.needsInput()) {
                    refillInflater(inflater);
                } else {
                    throw new IOException("Can't inflate " + length + " bytes");
                }
            } else {
                offset += read;
                length -= read;
            }
        } while(length > 0);
    } catch (DataFormatException ex) {
        throw (IOException)(new IOException("inflate error").initCause(ex));
    }
}
 
Example 18
Project: discord.jar   File: WebSocketClient.java   View source code 6 votes vote down vote up
@Override
public void onMessage(ByteBuffer message) {
	try {

		//Thanks to ShadowLordAlpha for code and debugging.
		//Get the compressed message and inflate it
		StringBuilder builder = new StringBuilder();
		Inflater decompresser = new Inflater();
		byte[] bytes = message.array();
		decompresser.setInput(bytes, 0, bytes.length);
		byte[] result = new byte[128];
		while (!decompresser.finished()) {
			int resultLength = decompresser.inflate(result);
			builder.append(new String(result, 0, resultLength, "UTF-8"));
		}
		decompresser.end();

		// send the inflated message to the TextMessage method
		onMessage(builder.toString());
	} catch (DataFormatException | UnsupportedEncodingException e) {
		e.printStackTrace();
	}
}
 
Example 19
Project: DIA-Umpire-Maven   File: DIAPack.java   View source code 6 votes vote down vote up
public void BuildDIAWindows() throws IOException, DataFormatException, IOException, IOException, IOException, InterruptedException {
    if (dIA_Setting.DIAWindows == null || dIA_Setting.DIAWindows.isEmpty()) {
        GetSpectrumParser();
    }
    DIAWindows = new ArrayList<>();
    Object[] WindowRange = dIA_Setting.DIAWindows.keySet().toArray();
    for (int i = 0; i < WindowRange.length; i++) {
        XYData DiaWinMz = (XYData) WindowRange[i];
        XYData LastWinMz = null;
        if (i < WindowRange.length - 1) {
            LastWinMz = (XYData) WindowRange[i + 1];
        }

        LCMSPeakDIAMS2 diawindow = new LCMSPeakDIAMS2(Filename, this, parameter, DiaWinMz, LastWinMz, GetSpectrumParser(), NoCPUs);
        diawindow.Resume = Resume;
        //pass the settings through to MS2 feature map
        diawindow.datattype = dIA_Setting.dataType;
        diawindow.ExportPeakCurveTable = ExportFragmentPeak;
        diawindow.ExportPeakClusterTable = ExportPrecursorPeak;
        DIAWindows.add(diawindow);
    }
}
 
Example 20
Project: JungleTree   File: ByteBufUtils.java   View source code 6 votes vote down vote up
public static byte[] inflate(byte[] input) {
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        Inflater inflater = new Inflater();
        inflater.setInput(input);

        byte[] intermediate = new byte[1024];
        while (!inflater.finished()) {
            int read = inflater.inflate(intermediate);
            out.write(intermediate, 0, read);
        }

        return out.toByteArray();
    } catch (DataFormatException ex) {
        throw new RuntimeException("Failed to inflate chunk data", ex);
    }
}
 
Example 21
Project: AndroidUtilCode-master   File: LogUtils.java   View source code 6 votes vote down vote up
public static byte[] uncompress(byte[] input) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Inflater decompressor = new Inflater();
    try {
        decompressor.setInput(input);
        final byte[] buf = new byte[2048];
        while (!decompressor.finished()) {
            int count = 0;
            try {
                count = decompressor.inflate(buf);
            } catch (DataFormatException e) {
                e.printStackTrace();
            }
            bos.write(buf, 0, count);
        }
    } finally {
        decompressor.end();
    }
    return bos.toByteArray();
}
 
Example 22
Project: oscm   File: RedirectSamlURLBuilderTest.java   View source code 6 votes vote down vote up
private String decodeURLBase64DeflateString(final String input)
        throws UnsupportedEncodingException, DataFormatException {
    String urlDecoded = URLDecoder.decode(input, "UTF-8");
    byte[] base64Decoded = Base64.decodeBase64(urlDecoded);

    Inflater decompresser = new Inflater(true);
    decompresser.setInput(base64Decoded);
    StringBuilder result = new StringBuilder();

    while (!decompresser.finished()) {
        byte[] outputFraction = new byte[base64Decoded.length];
        int resultLength = decompresser.inflate(outputFraction);
        result.append(new String(outputFraction, 0, resultLength, "UTF-8"));
    }

    return result.toString();
}
 
Example 23
Project: oscm   File: RedirectEncoderTest.java   View source code 6 votes vote down vote up
private String decodeURLBase64DeflateString(final String input)
        throws UnsupportedEncodingException, DataFormatException {
    String urlDecoded = URLDecoder.decode(input, "UTF-8");
    byte[] base64Decoded = Base64.decodeBase64(urlDecoded);

    Inflater decompresser = new Inflater(true);
    decompresser.setInput(base64Decoded);
    StringBuilder result = new StringBuilder();

    while (!decompresser.finished()) {
        byte[] outputFraction = new byte[base64Decoded.length];
        int resultLength = decompresser.inflate(outputFraction);
        result.append(new String(outputFraction, 0, resultLength, "UTF-8"));
    }

    return result.toString();
}
 
Example 24
Project: compress   File: DeflaterCompress.java   View source code 6 votes vote down vote up
@Override
public byte[] uncompress(byte[] data) throws IOException {
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	Inflater decompressor = new Inflater();
	
	try {
		decompressor.setInput(data);
		final byte[] buf = new byte[2048];
		while (!decompressor.finished()) {
			int count = decompressor.inflate(buf);
			bos.write(buf, 0, count);
		}
	} catch (DataFormatException e) {
		e.printStackTrace();
	} finally {
		decompressor.end();
	}
	
	return bos.toByteArray();
}
 
Example 25
Project: letv   File: bs.java   View source code 6 votes vote down vote up
public static byte[] b(byte[] bArr) throws UnsupportedEncodingException, DataFormatException {
    int i = 0;
    if (bArr == null || bArr.length == 0) {
        return null;
    }
    Inflater inflater = new Inflater();
    inflater.setInput(bArr, 0, bArr.length);
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    byte[] bArr2 = new byte[1024];
    while (!inflater.needsInput()) {
        int inflate = inflater.inflate(bArr2);
        byteArrayOutputStream.write(bArr2, i, inflate);
        i += inflate;
    }
    inflater.end();
    return byteArrayOutputStream.toByteArray();
}
 
Example 26
Project: lams   File: CompressionTools.java   View source code 6 votes vote down vote up
/** Decompress the byte array previously returned by
 *  compress */
public static byte[] decompress(byte[] value, int offset, int length) throws DataFormatException {
  // Create an expandable byte array to hold the decompressed data
  ByteArrayOutputStream bos = new ByteArrayOutputStream(length);

  Inflater decompressor = new Inflater();

  try {
    decompressor.setInput(value, offset, length);

    // Decompress the data
    final byte[] buf = new byte[1024];
    while (!decompressor.finished()) {
      int count = decompressor.inflate(buf);
      bos.write(buf, 0, count);
    }
  } finally {  
    decompressor.end();
  }
  
  return bos.toByteArray();
}
 
Example 27
Project: BaseClient   File: PNGDecoder.java   View source code 6 votes vote down vote up
private void readChunkUnzip(Inflater inflater, byte[] buffer, int offset, int length) throws IOException {
    try {
        do {
            int read = inflater.inflate(buffer, offset, length);
            if(read <= 0) {
                if(inflater.finished()) {
                    throw new EOFException();
                }
                if(inflater.needsInput()) {
                    refillInflater(inflater);
                } else {
                    throw new IOException("Can't inflate " + length + " bytes");
                }
            } else {
                offset += read;
                length -= read;
            }
        } while(length > 0);
    } catch (DataFormatException ex) {
        throw (IOException)(new IOException("inflate error").initCause(ex));
    }
}
 
Example 28
Project: fpm   File: PbfBlobDecoder.java   View source code 6 votes vote down vote up
public static byte[] inflate(PbfRawBlob rawBlob) throws InvalidProtocolBufferException {
    Blob blob = Blob.parseFrom(rawBlob.getData());
    byte[] blobData;
    if (blob.hasRaw()) {
        blobData = blob.getRaw().toByteArray();
    }
    else if (blob.hasZlibData()) {
        Inflater inflater = new Inflater();
        inflater.setInput(blob.getZlibData().toByteArray());
        blobData = new byte[blob.getRawSize()];
        try {
            inflater.inflate(blobData);
        }
        catch (DataFormatException e) {
            throw new OsmosisRuntimeException("Unable to decompress PBF blob.", e);
        }
        if (!inflater.finished()) {
            throw new OsmosisRuntimeException("PBF blob contains incomplete compressed data.");
        }
    }
    else {
        throw new OsmosisRuntimeException("PBF blob uses unsupported compression, only raw or zlib may be used.");
    }
    return blobData;
}
 
Example 29
Project: monarch   File: CliUtil.java   View source code 6 votes vote down vote up
public static DeflaterInflaterData uncompressBytes(byte[] output, int compressedDataLength)
    throws DataFormatException {
  Inflater decompresser = new Inflater();
  decompresser.setInput(output, 0, compressedDataLength);
  byte[] buffer = new byte[512];
  byte[] result = new byte[0];
  int bytesRead;
  while (!decompresser.needsInput()) {
    bytesRead = decompresser.inflate(buffer);
    byte[] newResult = new byte[result.length + bytesRead];
    System.arraycopy(result, 0, newResult, 0, result.length);
    System.arraycopy(buffer, 0, newResult, result.length, bytesRead);
    result = newResult;
  }
  // System.out.println(new String(result));
  decompresser.end();

  return new DeflaterInflaterData(result.length, result);
}
 
Example 30
Project: boohee_v5.6   File: bs.java   View source code 6 votes vote down vote up
public static byte[] b(byte[] bArr) throws UnsupportedEncodingException, DataFormatException {
    int i = 0;
    if (bArr == null || bArr.length == 0) {
        return null;
    }
    Inflater inflater = new Inflater();
    inflater.setInput(bArr, 0, bArr.length);
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    byte[] bArr2 = new byte[1024];
    while (!inflater.needsInput()) {
        int inflate = inflater.inflate(bArr2);
        byteArrayOutputStream.write(bArr2, i, inflate);
        i += inflate;
    }
    inflater.end();
    return byteArrayOutputStream.toByteArray();
}
 
Example 31
Project: boohee_v5.6   File: NameValueBlockReader.java   View source code 6 votes vote down vote up
public NameValueBlockReader(BufferedSource source) {
    this.inflaterSource = new InflaterSource(new ForwardingSource(source) {
        public long read(Buffer sink, long byteCount) throws IOException {
            if (NameValueBlockReader.this.compressedLimit == 0) {
                return -1;
            }
            long read = super.read(sink, Math.min(byteCount, (long) NameValueBlockReader.this
                    .compressedLimit));
            if (read == -1) {
                return -1;
            }
            NameValueBlockReader.this.compressedLimit = (int) (((long) NameValueBlockReader
                    .this.compressedLimit) - read);
            return read;
        }
    }, new Inflater() {
        public int inflate(byte[] buffer, int offset, int count) throws DataFormatException {
            int result = super.inflate(buffer, offset, count);
            if (result != 0 || !needsDictionary()) {
                return result;
            }
            setDictionary(Spdy3.DICTIONARY);
            return super.inflate(buffer, offset, count);
        }
    });
}
 
Example 32
Project: LoRaWAN-Smart-Parking   File: NameValueBlockReader.java   View source code 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 33
Project: LoRaWAN-Smart-Parking   File: NameValueBlockReader.java   View source code 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 34
Project: cr-private-server   File: DataStream.java   View source code 6 votes vote down vote up
public String getZipString() {
	int length = getBInt() - 4;
	int zlength = getLInt();

	if (remaining() > length) {
		Inflater decompressor = new Inflater();
		decompressor.setInput(buffer, offset, length);
		offset += length;

		try {
			ByteArrayOutputStream bos = new ByteArrayOutputStream(zlength);
			byte[] buf = new byte[1024];
			int count;
			while ((!decompressor.finished()) && ((count = decompressor.inflate(buf)) > 0)) {
				bos.write(buf, 0, count);
			}
			decompressor.end();
			bos.close();

			return new String(bos.toByteArray(), UTF8_CHARSET);
		} catch (DataFormatException | IOException ignored) {
		}
	}

	return null;
}
 
Example 35
Project: HeadlineNews   File: LogUtils.java   View source code 6 votes vote down vote up
public static byte[] uncompress(final byte[] input) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Inflater decompressor = new Inflater();
    try {
        decompressor.setInput(input);
        final byte[] buf = new byte[2048];
        while (!decompressor.finished()) {
            int count = 0;
            try {
                count = decompressor.inflate(buf);
            } catch (DataFormatException e) {
                e.printStackTrace();
            }
            bos.write(buf, 0, count);
        }
    } finally {
        decompressor.end();
    }
    return bos.toByteArray();
}
 
Example 36
Project: odb-little-fortune-planet   File: PNGDecoder.java   View source code 6 votes vote down vote up
private void readChunkUnzip(Inflater inflater, byte[] buffer, int offset, int length) throws IOException {
    assert(buffer != this.buffer);
    try {
        do {
            int read = inflater.inflate(buffer, offset, length);
            if(read <= 0) {
                if(inflater.finished()) {
                    throw new EOFException();
                }
                if(inflater.needsInput()) {
                    refillInflater(inflater);
                } else {
                    throw new IOException("Can't inflate " + length + " bytes");
                }
            } else {
                offset += read;
                length -= read;
            }
        } while(length > 0);
    } catch (DataFormatException ex) {
        throw (IOException)(new IOException("inflate error").initCause(ex));
    }
}
 
Example 37
Project: Towan   File: PNGDecoder.java   View source code 6 votes vote down vote up
private void readChunkUnzip(Inflater inflater, byte[] buffer, int offset, int length) throws IOException {
    try {
        do {
            int read = inflater.inflate(buffer, offset, length);
            if(read <= 0) {
                if(inflater.finished()) {
                    throw new EOFException();
                }
                if(inflater.needsInput()) {
                    refillInflater(inflater);
                } else {
                    throw new IOException("Can't inflate " + length + " bytes");
                }
            } else {
                offset += read;
                length -= read;
            }
        } while(length > 0);
    } catch (DataFormatException ex) {
        throw (IOException)(new IOException("inflate error").initCause(ex));
    }
}
 
Example 38
Project: automatic-variants   File: VariantProfile.java   View source code 6 votes vote down vote up
public boolean catalogNif(String nifPath) {
if (!nifInfoDatabase.containsKey(nifPath)) {
    try {
	LShrinkArray nifRawData = BSA.getUsedFile(nifPath);
	if (nifRawData != null) {
	    ArrayList<TextureSet> nifTextures = VariantFactory.loadNif(nifPath, nifRawData);
	    Map<Integer, TextureSet> nifData = new HashMap<>();
	    nifInfoDatabase.put(nifPath.toUpperCase(), nifData);
	    for (TextureSet t : nifTextures) {
		textures.put(t.getIndex(), t.getTextures());
		nifData.put(t.getIndex(), t);
	    }
	    return true;
	} else {
	    SPGlobal.log(toString(), " * Could not catalog nif because it could not find file: " + nifPath);
	}
    } catch (IOException | DataFormatException ex) {
	SPGlobal.logException(ex);
    }
}
return false;
   }
 
Example 39
Project: mi-firma-android   File: Ceres.java   View source code 6 votes vote down vote up
/** Descomprime un certificado contenido en la tarjeta CERES.
 * @param compressedCertificate Certificado comprimido en ZIP a partir del 9 octeto.
 * @return Certificado codificado.
 * @throws IOException Cuando se produce un error en la descompresi&oacute;n del certificado. */
private static byte[] deflate(final byte[] compressedCertificate) throws IOException {
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    final Inflater decompressor = new Inflater();
    decompressor.setInput(compressedCertificate, 8, compressedCertificate.length - 8);
    final byte[] buf = new byte[1024];
    try {
        // Descomprimimos los datos
        while (!decompressor.finished()) {
            final int count = decompressor.inflate(buf);
            if (count == 0) {
                throw new DataFormatException();
            }
            buffer.write(buf, 0, count);
        }
        // Obtenemos los datos descomprimidos
        return buffer.toByteArray();
    }
    catch (final DataFormatException ex) {
        throw new IOException("Error al descomprimir el certificado: " + ex, ex); //$NON-NLS-1$
    }
}
 
Example 40
Project: mi-firma-android   File: Dnie.java   View source code 6 votes vote down vote up
/** Descomprime un certificado contenido en el DNIe.
 * @param compressedCertificate Certificado comprimido en ZIP a partir del 9 byte.
 * @return Certificado codificado.
 * @throws IOException Cuando se produce un error en la descompresion del certificado. */
private static byte[] deflate(final byte[] compressedCertificate) throws IOException {
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    final Inflater decompressor = new Inflater();
    decompressor.setInput(compressedCertificate, 8, compressedCertificate.length - 8);
    final byte[] buf = new byte[1024];
    try {
        // Descomprimimos los datos
        while (!decompressor.finished()) {
            final int count = decompressor.inflate(buf);
            if (count == 0) {
                throw new DataFormatException();
            }
            buffer.write(buf, 0, count);
        }
        // Obtenemos los datos descomprimidos
        return buffer.toByteArray();
    }
    catch (final DataFormatException ex) {
        throw new IOException("Error al descomprimir el certificado: " + ex, ex); //$NON-NLS-1$
    }
}