Package java.io

Examples of java.io.FilterInputStream


                InputStream in = rs.getBinaryStream(1);
                /**
                 * return an InputStream wrapper in order to
                 * close the ResultSet when the stream is closed
                 */
                return new FilterInputStream(in) {
                    public void close() throws IOException {
                        super.close();
                        // close ResultSet
                        closeResultSet(rs);
                    }
View Full Code Here


    public void testReadFully() throws IOException {
        final Random r = new Random(1);
        byte[] data = new byte[1000];
        final AtomicInteger readCount = new AtomicInteger();
        r.nextBytes(data);
        FilterInputStream in = new FilterInputStream(new ByteArrayInputStream(data)) {
            public int read(byte[] buffer, int off, int max) throws IOException {
                readCount.incrementAndGet();
                if (r.nextInt(10) == 0) {
                    return 0;
                }
                return in.read(buffer, off, Math.min(10, max));
            }
        };
        in.mark(10000);
        byte[] test = new byte[1000];

        // readFully is not supposed to call read when reading 0 bytes
        assertEquals(0, IOUtils.readFully(in, test, 0, 0));
        assertEquals(0, readCount.get());

        assertEquals(1000, IOUtils.readFully(in, test, 0, 1000));
        IOUtilsTest.assertEquals(data, test);
        test = new byte[1001];
        in.reset();
        in.mark(10000);
        assertEquals(1000, IOUtils.readFully(in, test, 0, 1001));
        assertEquals(0, IOUtils.readFully(in, test, 0, 0));
    }
View Full Code Here

    public void testSkipFully() throws IOException {
        final Random r = new Random(1);
        byte[] data = new byte[1000];
        r.nextBytes(data);
        FilterInputStream in = new FilterInputStream(new ByteArrayInputStream(data)) {
            public int read(byte[] buffer, int off, int max) throws IOException {
                return in.read(buffer, off, Math.min(10, max));
            }
        };
        in.mark(10000);
        IOUtils.skipFully(in, 1000);
        assertEquals(-1, in.read());
        in.reset();
        try {
            IOUtils.skipFully(in, 1001);
            fail();
        } catch (EOFException e) {
            // expected
View Full Code Here

                }

                 // return an InputStream wrapper in order to close the ResultSet when the stream is closed
                close = false;
                final ResultSet rs2 = rs;
                return new FilterInputStream(in) {

                    public void close() throws IOException {
                        try {
                            in.close();
                        } finally {
View Full Code Here

      body = trimCrlf(buffer.toByteArray());

      // Remove CRLF from the boundary token (to match readLine)
      line = trimCrlf(line);
    } else {
      body = new FilterInputStream(ByteStreams.limit(inputStream, contentLength)) {
        @Override
        public void close() {
          // Don't allow the parser to close the underlying stream
        }
      };
View Full Code Here

    public InputStream getInputStream()
        throws java.io.IOException
    {    
        checkConnection();
        if (!_urlString.endsWith("!/"))
            return new FilterInputStream(super.getInputStream())
            {
                public void close() throws IOException {this.in=IO.getClosedStream();}
            };

        URL url = new URL(_urlString.substring(4,_urlString.length()-2));     
View Full Code Here

            /**
             * return an InputStream wrapper in order to
             * close the ResultSet when the stream is closed
             */
            return new FilterInputStream(in) {
                public void close() throws IOException {
                    in.close();
                    // now it's safe to close ResultSet
                    closeResultSet(rs);
                }
View Full Code Here

    public void load() throws IOException {
        if (features == null) {
            try {
                InputStream inputStream = uri.toURL().openStream();
                inputStream = new FilterInputStream(inputStream) {
            @Override
            public int read(byte b[], int off, int len) throws IOException {
              if (Thread.currentThread().isInterrupted()) {
                throw new InterruptedIOException();
              }
View Full Code Here

                is.close();
                is = new URL(bundleLocation).openStream();
                // is = new BufferedInputStream(new
                // URL(bundleLocation).openStream());
            }
            is = new BufferedInputStream(new FilterInputStream(is) {
                @Override
                public int read(byte b[], int off, int len) throws IOException {
                    if (Thread.currentThread().isInterrupted()) {
                        throw new InterruptedIOException();
                    }
View Full Code Here

        is.close();
        is = new URL(bundleLocation).openStream();
        // is = new BufferedInputStream(new
        // URL(bundleLocation).openStream());
      }
      is = new BufferedInputStream(new FilterInputStream(is) {
        @Override
        public int read(byte b[], int off, int len) throws IOException {
          if (Thread.currentThread().isInterrupted()) {
            throw new InterruptedIOException();
          }
View Full Code Here

TOP

Related Classes of java.io.FilterInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.