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 File: LineDisciplineTerminal.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
public LineDisciplineTerminal(String name,
                              String type,
                              OutputStream masterOutput) throws IOException {
    super(name, type);
    PipedInputStream input = new LinePipedInputStream(PIPE_SIZE);
    this.slaveInputPipe = new PipedOutputStream(input);
    // This is a hack to fix a problem in gogo where closure closes
    // streams for commands if they are instances of PipedInputStream.
    // So we need to get around and make sure it's not an instance of
    // that class by using a dumb FilterInputStream class to wrap it.
    this.slaveInput = new FilterInputStream(input) {};
    this.slaveOutput = new FilteringOutputStream();
    this.masterOutput = masterOutput;
    this.attributes = new Attributes();
    this.size = new Size(160, 50);
}
 
Example #2
Source File: TemplateVars.java    From auto with Apache License 2.0 6 votes vote down vote up
private static InputStream inputStreamFromJar(URL resourceUrl)
    throws URISyntaxException, IOException {
  // Jar URLs look like this: jar:file:/path/to/file.jar!/entry/within/jar
  // So take apart the URL to open the jar /path/to/file.jar and read the entry
  // entry/within/jar from it.
  String resourceUrlString = resourceUrl.toString().substring("jar:".length());
  int bang = resourceUrlString.lastIndexOf('!');
  String entryName = resourceUrlString.substring(bang + 1);
  if (entryName.startsWith("/")) {
    entryName = entryName.substring(1);
  }
  URI jarUri = new URI(resourceUrlString.substring(0, bang));
  JarFile jar = new JarFile(new File(jarUri));
  JarEntry entry = jar.getJarEntry(entryName);
  InputStream in = jar.getInputStream(entry);
  // We have to be careful not to close the JarFile before the stream has been read, because
  // that would also close the stream. So we defer closing the JarFile until the stream is closed.
  return new FilterInputStream(in) {
    @Override
    public void close() throws IOException {
      super.close();
      jar.close();
    }
  };
}
 
Example #3
Source File: ClassReader.java    From jdk8u_jdk with 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 #4
Source File: BandStructure.java    From jdk8u-jdk with 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 #5
Source File: PackageReader.java    From openjdk-8 with 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 File: ClassReader.java    From openjdk-8 with 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 #7
Source File: BandStructure.java    From openjdk-8 with 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 #8
Source File: BandStructure.java    From jdk8u_jdk with 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 #9
Source File: JarResource.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
@Override
public InputStream getInputStream()
    throws java.io.IOException
{     
    checkConnection();
    if (!_urlString.endsWith("!/"))
        return new FilterInputStream(super.getInputStream()) 
        {
            @Override
            public void close() throws IOException {this.in=IO.getClosedStream();}
        };

    URL url = new URL(_urlString.substring(4,_urlString.length()-2));      
    InputStream is = url.openStream();
    return is;
}
 
Example #10
Source File: BandStructure.java    From jdk8u-jdk with 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 #11
Source File: ClassReader.java    From jdk8u-jdk with 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 #12
Source File: PackageReader.java    From jdk8u-jdk with 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 #13
Source File: NamedPipeSocket.java    From docker-client with 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 (inputShutdown) {
    throw new SocketException("Socket input is shutdown");
  }

  return new FilterInputStream(Channels.newInputStream(channel)) {
    @Override
    public void close() throws IOException {
      shutdownInput();
    }
  };
}
 
Example #14
Source File: ClassReader.java    From jdk8u-dev-jdk with 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 #15
Source File: PackageReader.java    From jdk8u-dev-jdk with 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 #16
Source File: PackageReader.java    From openjdk-8-source with 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 #17
Source File: MeteredInputStream.java    From incubator-gobblin with 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 #18
Source File: BandStructure.java    From openjdk-8-source with 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 File: PackageReader.java    From hottub with 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 #20
Source File: BandStructure.java    From hottub with 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 #21
Source File: GifLoadTask.java    From sctalk with 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 #22
Source File: PackageReader.java    From jdk8u-jdk with 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 #23
Source File: TransportCompressionTest.java    From grpc-nebula-java with 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 #24
Source File: DefaultInvocationBuilder.java    From docker-java with 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 #25
Source File: PackageReader.java    From openjdk-jdk9 with 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 #26
Source File: ClassReader.java    From openjdk-jdk9 with 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 #27
Source File: BandStructure.java    From openjdk-jdk9 with 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 File: PackageReader.java    From openjdk-jdk8u-backup with 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 #29
Source File: ClassReader.java    From openjdk-jdk8u-backup with 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 #30
Source File: BandStructure.java    From openjdk-jdk8u-backup with 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();
}