org.apache.commons.compress.utils.BoundedInputStream Java Examples

The following examples show how to use org.apache.commons.compress.utils.BoundedInputStream. 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: ScatterZipOutputStream.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
void writeTo(ZipArchiveOutputStream target) throws IOException {
    entryStore.closeForWriting();
    backingStore.closeForWriting();
    String line;

    try (InputStream stream = backingStore.getInputStream();
         BufferedReader reader = new BufferedReader(new InputStreamReader(entryStore.getInputStream(), StandardCharsets.UTF_8))) {
        while ((line = reader.readLine()) != null) {
            String[] values = line.split(",");
            if (values.length != 5)
                throw new IOException("Failed to read temporary zip entry.");

            ZipArchiveEntry entry = new ZipArchiveEntry(values[0]);
            entry.setMethod(Integer.parseInt(values[1]));
            entry.setCrc(Long.parseLong(values[2]));
            entry.setCompressedSize(Long.parseLong(values[3]));
            entry.setSize(Long.parseLong(values[4]));

            try (BoundedInputStream rawStream = new BoundedInputStream(stream, entry.getCompressedSize())) {
                target.addRawArchiveEntry(entry, rawStream);
            }
        }
    } catch (NumberFormatException e) {
        throw new IOException("Failed to read temporary zip entry.", e);
    }
}
 
Example #2
Source File: JavaBinCodecCoder.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public T decode(InputStream inStream) throws IOException {
  DataInputStream in = new DataInputStream(inStream);

  int len = VarInt.decodeInt(in);
  if (len < 0) {
    throw new CoderException("Invalid encoded SolrDocument length: " + len);
  }

  JavaBinCodec codec = new JavaBinCodec();
  return (T) codec.unmarshal(new BoundedInputStream(in, len));
}