Package java.io

Examples of java.io.BufferedInputStream.available()


    private void readTextFile( String fileName ) {
        try {
            String fileText, textLines[];
            BufferedInputStream bis =
              new BufferedInputStream( new FileInputStream( fileName ));
            int numBytes = bis.available();
            if (numBytes == 0) {
                throw new Exception("Text file " + fileName + " is empty");
            }
            byte byteData[] = new byte[ numBytes ];
            bis.read( byteData, 0, numBytes );
View Full Code Here


    /// Loads saved options and applies them
    private void loadOptions( String fileName ) {
        try {
            BufferedInputStream bis =
              new BufferedInputStream( new FileInputStream( fileName ));
            int numBytes = bis.available();
            byte byteData[] = new byte[ numBytes ];
            bis.read( byteData, 0, numBytes );
            bis.close();
            if ( numBytes < 2 ||
                (byteData[0] != (byte) 0xFE || byteData[1] != (byte) 0xFF) )
View Full Code Here

            try {
                Certificate cert = null;
                final ByteArrayInputStream bais = new ByteArrayInputStream(tmpkey.getBytes());
                final BufferedInputStream bis = new BufferedInputStream(bais);
                final CertificateFactory certfac = CertificateFactory.getInstance("X.509");
                while (bis.available() > 0) {
                    cert = certfac.generateCertificate(bis);
                }
                rsaPubKey = (RSAPublicKey) cert.getPublicKey();
            } catch (final Exception ex) {
                LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_CANNOT_OBTAIN_PUBLIC_KEY(), ex);
View Full Code Here

            InputStream stream = connection.getInputStream();
            Debug.log("getContentLength is :"+contentLength);

            in = new BufferedInputStream(stream);

            long totalBytes = in.available();
            Debug.log("totalBytes is : "+totalBytes);

            byte[] b = new byte[1024];

            FileOutputStream file = new FileOutputStream(libPath);
View Full Code Here

                // So we just read without blocking, because we do not know when to
                // stop reading, so we cannot block
                // TODO propery implement support for chunked transfer, i.e. to
                // know when we have read the whole request, and therefore allow
                // the reading to block
                while(in.available() > 0 && ((length = in.read(buffer)) != -1)) {
                    out.write(buffer, 0, length);
                }
            }
            else {
                // The reqest has no body, or it has a transfer encoding we do not support.
View Full Code Here

                }
            }
            else {
                // The reqest has no body, or it has a transfer encoding we do not support.
                // In either case, we read any data available
                while(in.available() > 0 && ((length = in.read(buffer)) != -1)) {
                    out.write(buffer, 0, length);
                }
            }
            out.flush();
        } catch (IOException e) {
View Full Code Here

    BufferedInputStream bis = new BufferedInputStream(
        new ByteArrayInputStream(new byte[] { 'h', 'e', 'l', 'l', 'o',
            ' ', 't', 'i', 'm' }));
    int available;
    try {
      available = bis.available();
      bis.close();
    } catch (IOException ex) {
      fail();
      return; // never reached.
    }
View Full Code Here

      return; // never reached.
    }
    assertTrue(available != 0);

    try {
      bis.available();
      fail("Expected test to throw IOE.");
    } catch (IOException ex) {
      // expected
    }
  }
View Full Code Here

            public void process(Exchange exchange) throws Exception {
             // Read from an input stream
                InputStream is = new BufferedInputStream(
                    new FileInputStream("./src/test/resources/test.txt"));

                byte buffer[] = new byte[is.available()];
                int n = is.available();
                for (int i = 0; i < n; i++) {
                    buffer[i] = (byte)is.read();
                }
View Full Code Here

             // Read from an input stream
                InputStream is = new BufferedInputStream(
                    new FileInputStream("./src/test/resources/test.txt"));

                byte buffer[] = new byte[is.available()];
                int n = is.available();
                for (int i = 0; i < n; i++) {
                    buffer[i] = (byte)is.read();
                }

                is.close();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.