java.io.FilterInputStream Java Examples

The following examples show how to use java.io.FilterInputStream. 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: grpc-nebula-java   Author: grpc-nebula   File: TransportCompressionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public InputStream decompress(InputStream is) throws IOException {
  return new FilterInputStream(delegate.decompress(is)) {
    @Override
    public int read() throws IOException {
      int val = super.read();
      anyRead = true;
      return val;
    }

    @Override
    public int read(byte[] b, int off, int len) throws IOException {
      int total = super.read(b, off, len);
      anyRead = true;
      return total;
    }
  };
}
 
Example #2
Source Project: jkube   Author: eclipse   File: UnixSocket.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public InputStream getInputStream() throws IOException {
    if (!channel.isOpen()) {
        throw new SocketException("Socket is closed");
    }

    if (!channel.isConnected()) {
        throw new SocketException("Socket is not connected");
    }

    if (inputShutdown) {
        throw new SocketException("Socket input is shutdown");
    }

    return new FilterInputStream(Channels.newInputStream(channel)) {
        @Override
        public void close() throws IOException {
            shutdownInput();
        }
    };
}
 
Example #3
Source Project: jkube   Author: eclipse   File: NamedPipe.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public InputStream getInputStream() throws IOException {
    if (!channel.isOpen()) {
        throw new SocketException("Socket is closed");
    }

    if (inputShutdown) {
        throw new SocketException("Socket input is shutdown");
    }

    return new FilterInputStream(Channels.newInputStream(channel)) {

        @Override
        public int read(byte[] b, int off, int len) throws IOException {
            int readed = super.read(b, off, len);
            log.debug("RESPONSE %s", new String(b, off, len, StandardCharsets.UTF_8));
            return readed;
        }

        @Override
        public void close() throws IOException {
            shutdownInput();
        }
    };
}
 
Example #4
Source Project: ShizuruNotes   Author: MalitsPlus   File: BundleChecker.java    License: Apache License 2.0 6 votes vote down vote up
private long decompressAndCalculateCrc(ZipInputStream input) throws IOException {
  /* Do not allow entry readers to close the whole ZipInputStream. */
  FilterInputStream entryStream = new FilterInputStream(input) {
    @Override
    public void close() {}
  };

  BrotliInputStream decompressedStream = new BrotliInputStream(entryStream);
  long crc;
  try {
    crc = BundleHelper.fingerprintStream(decompressedStream);
  } finally {
    decompressedStream.close();
  }
  return crc;
}
 
Example #5
Source Project: dragonwell8_jdk   Author: alibaba   File: PackageReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
LimitedBuffer(InputStream originalIn) {
    super(null, 1<<14);
    servedPos = pos;
    super.in = new FilterInputStream(originalIn) {
        public int read() throws IOException {
            if (buffered == limit)
                return -1;
            ++buffered;
            return super.read();
        }
        public int read(byte b[], int off, int len) throws IOException {
            if (buffered == limit)
                return -1;
            if (limit != -1) {
                long remaining = limit - buffered;
                if (len > remaining)
                    len = (int)remaining;
            }
            int nr = super.read(b, off, len);
            if (nr >= 0)  buffered += nr;
            return nr;
        }
    };
}
 
Example #6
Source Project: TencentKona-8   Author: Tencent   File: BandStructure.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void setInputStreamFrom(InputStream in) throws IOException {
    assert(bytes == null);
    assert(assertReadyToReadFrom(this, in));
    setPhase(READ_PHASE);
    this.in = in;
    if (optDumpBands) {
        // Tap the stream.
        bytesForDump = new ByteArrayOutputStream();
        this.in = new FilterInputStream(in) {
            @Override
            public int read() throws IOException {
                int ch = in.read();
                if (ch >= 0)  bytesForDump.write(ch);
                return ch;
            }
            @Override
            public int read(byte b[], int off, int len) throws IOException {
                int nr = in.read(b, off, len);
                if (nr >= 0)  bytesForDump.write(b, off, nr);
                return nr;
            }
        };
    }
    super.readyToDisburse();
}
 
Example #7
Source Project: TencentKona-8   Author: Tencent   File: ClassReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
ClassReader(Class cls, InputStream in) throws IOException {
    this.pkg = cls.getPackage();
    this.cls = cls;
    this.verbose = pkg.verbose;
    this.in = new DataInputStream(new FilterInputStream(in) {
        public int read(byte b[], int off, int len) throws IOException {
            int nr = super.read(b, off, len);
            if (nr >= 0)  inPos += nr;
            return nr;
        }
        public int read() throws IOException {
            int ch = super.read();
            if (ch >= 0)  inPos += 1;
            return ch;
        }
        public long skip(long n) throws IOException {
            long ns = super.skip(n);
            if (ns >= 0)  inPos += ns;
            return ns;
        }
    });
}
 
Example #8
Source Project: TencentKona-8   Author: Tencent   File: PackageReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
LimitedBuffer(InputStream originalIn) {
    super(null, 1<<14);
    servedPos = pos;
    super.in = new FilterInputStream(originalIn) {
        public int read() throws IOException {
            if (buffered == limit)
                return -1;
            ++buffered;
            return super.read();
        }
        public int read(byte b[], int off, int len) throws IOException {
            if (buffered == limit)
                return -1;
            if (limit != -1) {
                long remaining = limit - buffered;
                if (len > remaining)
                    len = (int)remaining;
            }
            int nr = super.read(b, off, len);
            if (nr >= 0)  buffered += nr;
            return nr;
        }
    };
}
 
Example #9
Source Project: jdk8u60   Author: chenghanpeng   File: BandStructure.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void setInputStreamFrom(InputStream in) throws IOException {
    assert(bytes == null);
    assert(assertReadyToReadFrom(this, in));
    setPhase(READ_PHASE);
    this.in = in;
    if (optDumpBands) {
        // Tap the stream.
        bytesForDump = new ByteArrayOutputStream();
        this.in = new FilterInputStream(in) {
            @Override
            public int read() throws IOException {
                int ch = in.read();
                if (ch >= 0)  bytesForDump.write(ch);
                return ch;
            }
            @Override
            public int read(byte b[], int off, int len) throws IOException {
                int nr = in.read(b, off, len);
                if (nr >= 0)  bytesForDump.write(b, off, nr);
                return nr;
            }
        };
    }
    super.readyToDisburse();
}
 
Example #10
Source Project: docker-java   Author: docker-java   File: DefaultInvocationBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public InputStream post(Object entity) {
    DockerHttpClient.Request request = requestBuilder
        .method(DockerHttpClient.Request.Method.POST)
        .putHeader("content-type", "application/json")
        .body(encode(entity))
        .build();

    DockerHttpClient.Response response = execute(request);
    return new FilterInputStream(response.getBody()) {
        @Override
        public void close() throws IOException {
            try {
                super.close();
            } finally {
                response.close();
            }
        }
    };
}
 
Example #11
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: BandStructure.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void setInputStreamFrom(InputStream in) throws IOException {
    assert(bytes == null);
    assert(assertReadyToReadFrom(this, in));
    setPhase(READ_PHASE);
    this.in = in;
    if (optDumpBands) {
        // Tap the stream.
        bytesForDump = new ByteArrayOutputStream();
        this.in = new FilterInputStream(in) {
            @Override
            public int read() throws IOException {
                int ch = in.read();
                if (ch >= 0)  bytesForDump.write(ch);
                return ch;
            }
            @Override
            public int read(byte b[], int off, int len) throws IOException {
                int nr = in.read(b, off, len);
                if (nr >= 0)  bytesForDump.write(b, off, nr);
                return nr;
            }
        };
    }
    super.readyToDisburse();
}
 
Example #12
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ClassReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
ClassReader(Class cls, InputStream in) throws IOException {
    this.pkg = cls.getPackage();
    this.cls = cls;
    this.verbose = pkg.verbose;
    this.in = new DataInputStream(new FilterInputStream(in) {
        public int read(byte b[], int off, int len) throws IOException {
            int nr = super.read(b, off, len);
            if (nr >= 0)  inPos += nr;
            return nr;
        }
        public int read() throws IOException {
            int ch = super.read();
            if (ch >= 0)  inPos += 1;
            return ch;
        }
        public long skip(long n) throws IOException {
            long ns = super.skip(n);
            if (ns >= 0)  inPos += ns;
            return ns;
        }
    });
}
 
Example #13
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: PackageReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
LimitedBuffer(InputStream originalIn) {
    super(null, 1<<14);
    servedPos = pos;
    super.in = new FilterInputStream(originalIn) {
        public int read() throws IOException {
            if (buffered == limit)
                return -1;
            ++buffered;
            return super.read();
        }
        public int read(byte b[], int off, int len) throws IOException {
            if (buffered == limit)
                return -1;
            if (limit != -1) {
                long remaining = limit - buffered;
                if (len > remaining)
                    len = (int)remaining;
            }
            int nr = super.read(b, off, len);
            if (nr >= 0)  buffered += nr;
            return nr;
        }
    };
}
 
Example #14
Source Project: docker-maven-plugin   Author: fabric8io   File: UnixSocket.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public InputStream getInputStream() throws IOException {
    if (!channel.isOpen()) {
        throw new SocketException("Socket is closed");
    }

    if (!channel.isConnected()) {
        throw new SocketException("Socket is not connected");
    }

    if (inputShutdown) {
        throw new SocketException("Socket input is shutdown");
    }

    return new FilterInputStream(Channels.newInputStream(channel)) {
        @Override
        public void close() throws IOException {
            shutdownInput();
        }
    };
}
 
Example #15
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: BandStructure.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void setInputStreamFrom(InputStream in) throws IOException {
    assert(bytes == null);
    assert(assertReadyToReadFrom(this, in));
    setPhase(READ_PHASE);
    this.in = in;
    if (optDumpBands) {
        // Tap the stream.
        bytesForDump = new ByteArrayOutputStream();
        this.in = new FilterInputStream(in) {
            @Override
            public int read() throws IOException {
                int ch = in.read();
                if (ch >= 0)  bytesForDump.write(ch);
                return ch;
            }
            @Override
            public int read(byte b[], int off, int len) throws IOException {
                int nr = in.read(b, off, len);
                if (nr >= 0)  bytesForDump.write(b, off, nr);
                return nr;
            }
        };
    }
    super.readyToDisburse();
}
 
Example #16
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ClassReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
ClassReader(Class cls, InputStream in) throws IOException {
    this.pkg = cls.getPackage();
    this.cls = cls;
    this.verbose = pkg.verbose;
    this.in = new DataInputStream(new FilterInputStream(in) {
        public int read(byte b[], int off, int len) throws IOException {
            int nr = super.read(b, off, len);
            if (nr >= 0)  inPos += nr;
            return nr;
        }
        public int read() throws IOException {
            int ch = super.read();
            if (ch >= 0)  inPos += 1;
            return ch;
        }
        public long skip(long n) throws IOException {
            long ns = super.skip(n);
            if (ns >= 0)  inPos += ns;
            return ns;
        }
    });
}
 
Example #17
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: PackageReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
LimitedBuffer(InputStream originalIn) {
    super(null, 1<<14);
    servedPos = pos;
    super.in = new FilterInputStream(originalIn) {
        public int read() throws IOException {
            if (buffered == limit)
                return -1;
            ++buffered;
            return super.read();
        }
        public int read(byte b[], int off, int len) throws IOException {
            if (buffered == limit)
                return -1;
            if (limit != -1) {
                long remaining = limit - buffered;
                if (len > remaining)
                    len = (int)remaining;
            }
            int nr = super.read(b, off, len);
            if (nr >= 0)  buffered += nr;
            return nr;
        }
    };
}
 
Example #18
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: BandStructure.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void setInputStreamFrom(InputStream in) throws IOException {
    assert(bytes == null);
    assert(assertReadyToReadFrom(this, in));
    setPhase(READ_PHASE);
    this.in = in;
    if (optDumpBands) {
        // Tap the stream.
        bytesForDump = new ByteArrayOutputStream();
        this.in = new FilterInputStream(in) {
            @Override
            public int read() throws IOException {
                int ch = in.read();
                if (ch >= 0)  bytesForDump.write(ch);
                return ch;
            }
            @Override
            public int read(byte b[], int off, int len) throws IOException {
                int nr = in.read(b, off, len);
                if (nr >= 0)  bytesForDump.write(b, off, nr);
                return nr;
            }
        };
    }
    super.readyToDisburse();
}
 
Example #19
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ClassReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
ClassReader(Class cls, InputStream in) throws IOException {
    this.pkg = cls.getPackage();
    this.cls = cls;
    this.verbose = pkg.verbose;
    this.in = new DataInputStream(new FilterInputStream(in) {
        public int read(byte b[], int off, int len) throws IOException {
            int nr = super.read(b, off, len);
            if (nr >= 0)  inPos += nr;
            return nr;
        }
        public int read() throws IOException {
            int ch = super.read();
            if (ch >= 0)  inPos += 1;
            return ch;
        }
        public long skip(long n) throws IOException {
            long ns = super.skip(n);
            if (ns >= 0)  inPos += ns;
            return ns;
        }
    });
}
 
Example #20
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: PackageReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
LimitedBuffer(InputStream originalIn) {
    super(null, 1<<14);
    servedPos = pos;
    super.in = new FilterInputStream(originalIn) {
        public int read() throws IOException {
            if (buffered == limit)
                return -1;
            ++buffered;
            return super.read();
        }
        public int read(byte b[], int off, int len) throws IOException {
            if (buffered == limit)
                return -1;
            if (limit != -1) {
                long remaining = limit - buffered;
                if (len > remaining)
                    len = (int)remaining;
            }
            int nr = super.read(b, off, len);
            if (nr >= 0)  buffered += nr;
            return nr;
        }
    };
}
 
Example #21
Source Project: docker-java   Author: docker-java   File: DefaultInvocationBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public InputStream get() {
    DockerHttpClient.Request request = requestBuilder
        .method(DockerHttpClient.Request.Method.GET)
        .build();

    DockerHttpClient.Response response = execute(request);
    return new FilterInputStream(response.getBody()) {
        @Override
        public void close() throws IOException {
            try {
                super.close();
            } finally {
                response.close();
            }
        }
    };
}
 
Example #22
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: BandStructure.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void setInputStreamFrom(InputStream in) throws IOException {
    assert(bytes == null);
    assert(assertReadyToReadFrom(this, in));
    setPhase(READ_PHASE);
    this.in = in;
    if (optDumpBands) {
        // Tap the stream.
        bytesForDump = new ByteArrayOutputStream();
        this.in = new FilterInputStream(in) {
            @Override
            public int read() throws IOException {
                int ch = in.read();
                if (ch >= 0)  bytesForDump.write(ch);
                return ch;
            }
            @Override
            public int read(byte b[], int off, int len) throws IOException {
                int nr = in.read(b, off, len);
                if (nr >= 0)  bytesForDump.write(b, off, nr);
                return nr;
            }
        };
    }
    super.readyToDisburse();
}
 
Example #23
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: PackageReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
LimitedBuffer(InputStream originalIn) {
    super(null, 1<<14);
    servedPos = pos;
    super.in = new FilterInputStream(originalIn) {
        public int read() throws IOException {
            if (buffered == limit)
                return -1;
            ++buffered;
            return super.read();
        }
        public int read(byte b[], int off, int len) throws IOException {
            if (buffered == limit)
                return -1;
            if (limit != -1) {
                long remaining = limit - buffered;
                if (len > remaining)
                    len = (int)remaining;
            }
            int nr = super.read(b, off, len);
            if (nr >= 0)  buffered += nr;
            return nr;
        }
    };
}
 
Example #24
Source Project: sctalk   Author: ccfish86   File: GifLoadTask.java    License: Apache License 2.0 6 votes vote down vote up
private FilterInputStream getFromCache(String url) throws Exception {
    DiskLruCache cache = DiskLruCache.open(CommonUtil.getImageSavePath(), 1, 2, 2*1024*1024);
    cache.flush();
    String key = Util.hash(url);
    final DiskLruCache.Snapshot snapshot;
    try {
        snapshot = cache.get(key);
        if (snapshot == null) {
            return null;
        }
    } catch (IOException e) {
        return null;
    }
    FilterInputStream bodyIn = new FilterInputStream(snapshot.getInputStream(1)) {
        @Override
        public void close() throws IOException {
            snapshot.close();
            super.close();
        }
    };
    return bodyIn;
}
 
Example #25
Source Project: hottub   Author: dsrg-uoft   File: BandStructure.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void setInputStreamFrom(InputStream in) throws IOException {
    assert(bytes == null);
    assert(assertReadyToReadFrom(this, in));
    setPhase(READ_PHASE);
    this.in = in;
    if (optDumpBands) {
        // Tap the stream.
        bytesForDump = new ByteArrayOutputStream();
        this.in = new FilterInputStream(in) {
            @Override
            public int read() throws IOException {
                int ch = in.read();
                if (ch >= 0)  bytesForDump.write(ch);
                return ch;
            }
            @Override
            public int read(byte b[], int off, int len) throws IOException {
                int nr = in.read(b, off, len);
                if (nr >= 0)  bytesForDump.write(b, off, nr);
                return nr;
            }
        };
    }
    super.readyToDisburse();
}
 
Example #26
Source Project: hottub   Author: dsrg-uoft   File: PackageReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
LimitedBuffer(InputStream originalIn) {
    super(null, 1<<14);
    servedPos = pos;
    super.in = new FilterInputStream(originalIn) {
        public int read() throws IOException {
            if (buffered == limit)
                return -1;
            ++buffered;
            return super.read();
        }
        public int read(byte b[], int off, int len) throws IOException {
            if (buffered == limit)
                return -1;
            if (limit != -1) {
                long remaining = limit - buffered;
                if (len > remaining)
                    len = (int)remaining;
            }
            int nr = super.read(b, off, len);
            if (nr >= 0)  buffered += nr;
            return nr;
        }
    };
}
 
Example #27
Source Project: openjdk-8-source   Author: keerath   File: BandStructure.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void setInputStreamFrom(InputStream in) throws IOException {
    assert(bytes == null);
    assert(assertReadyToReadFrom(this, in));
    setPhase(READ_PHASE);
    this.in = in;
    if (optDumpBands) {
        // Tap the stream.
        bytesForDump = new ByteArrayOutputStream();
        this.in = new FilterInputStream(in) {
            @Override
            public int read() throws IOException {
                int ch = in.read();
                if (ch >= 0)  bytesForDump.write(ch);
                return ch;
            }
            @Override
            public int read(byte b[], int off, int len) throws IOException {
                int nr = in.read(b, off, len);
                if (nr >= 0)  bytesForDump.write(b, off, nr);
                return nr;
            }
        };
    }
    super.readyToDisburse();
}
 
Example #28
Source Project: incubator-gobblin   Author: apache   File: MeteredInputStream.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Find the lowest {@link MeteredInputStream} in a chain of {@link FilterInputStream}s.
 */
public static Optional<MeteredInputStream> findWrappedMeteredInputStream(InputStream is) {
  if (is instanceof FilterInputStream) {
    try {
      Optional<MeteredInputStream> meteredInputStream =
          findWrappedMeteredInputStream(FilterStreamUnpacker.unpackFilterInputStream((FilterInputStream) is));
      if (meteredInputStream.isPresent()) {
        return meteredInputStream;
      }
    } catch (IllegalAccessException iae) {
      log.warn("Cannot unpack input stream due to SecurityManager.", iae);
      // Do nothing, we can't unpack the FilterInputStream due to security restrictions
    }
  }
  if (is instanceof MeteredInputStream) {
    return Optional.of((MeteredInputStream) is);
  }
  return Optional.absent();
}
 
Example #29
Source Project: openjdk-8-source   Author: keerath   File: PackageReader.java    License: GNU General Public License v2.0 6 votes vote down vote up
LimitedBuffer(InputStream originalIn) {
    super(null, 1<<14);
    servedPos = pos;
    super.in = new FilterInputStream(originalIn) {
        public int read() throws IOException {
            if (buffered == limit)
                return -1;
            ++buffered;
            return super.read();
        }
        public int read(byte b[], int off, int len) throws IOException {
            if (buffered == limit)
                return -1;
            if (limit != -1) {
                long remaining = limit - buffered;
                if (len > remaining)
                    len = (int)remaining;
            }
            int nr = super.read(b, off, len);
            if (nr >= 0)  buffered += nr;
            return nr;
        }
    };
}
 
Example #30
Source Project: openjdk-8   Author: bpupadhyaya   File: BandStructure.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void setInputStreamFrom(InputStream in) throws IOException {
    assert(bytes == null);
    assert(assertReadyToReadFrom(this, in));
    setPhase(READ_PHASE);
    this.in = in;
    if (optDumpBands) {
        // Tap the stream.
        bytesForDump = new ByteArrayOutputStream();
        this.in = new FilterInputStream(in) {
            @Override
            public int read() throws IOException {
                int ch = in.read();
                if (ch >= 0)  bytesForDump.write(ch);
                return ch;
            }
            @Override
            public int read(byte b[], int off, int len) throws IOException {
                int nr = in.read(b, off, len);
                if (nr >= 0)  bytesForDump.write(b, off, nr);
                return nr;
            }
        };
    }
    super.readyToDisburse();
}