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

The following examples show how to use org.apache.commons.compress.utils.BoundedInputStream. These examples are extracted from open source projects. 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 Project: importer-exporter   Source File:    License: Apache License 2.0 6 votes vote down vote up
void writeTo(ZipArchiveOutputStream target) throws IOException {
    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]);

            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 Project: beam   Source File:    License: Apache License 2.0 5 votes vote down vote up
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));