Package java.io

Examples of java.io.BufferedInputStream


            tempHeader = (Instances) v.elementAt(1);
          }
        } /* binary */ else {

          ObjectInputStream is =
            new ObjectInputStream(new BufferedInputStream(
                                                          new FileInputStream(loadFrom)));
          // try and read the model
          temp = (weka.classifiers.Classifier)is.readObject();
          // try and read the header (if present)
          try {
View Full Code Here


        if (file.equalsIgnoreCase("-url"))
        {
      if (args.length > 1)
      {
        URL u = new URL(args[1]);
            Player player = new Player(new BufferedInputStream(u.openStream(), 2048));
            System.out.println("starting");
            player.play();
            System.out.println("ending");
      }
      else
      {
        usage();
      }
    }
    else
    {
          Player player = new Player(new BufferedInputStream(new FileInputStream(file), 2048));
          System.out.println("starting");
          player.play();
          System.out.println("ending");
    }
      }
View Full Code Here

    ObjectInputStream in=null;
   
    try {
      File programConfigFile = new File(Settings.getUserSettingsDirName(),"programConfigurations.dat");
     
      in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(programConfigFile), 0x1000));
     
      in.readInt(); // read version
     
      mAvailableProgramConfigurations = new GlobalPluginProgramFormating[in.readInt()];
     
View Full Code Here

  private void loadServiceSettings(TvDataServiceProxy service) {
    File f=new File(Settings.getUserSettingsDirName(),service.getId()+".service");
    if (f.exists()) {
      try {
        Properties p=new Properties();
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(f), 0x1000);
        p.load(in);
        in.close();
        service.loadSettings(p);
      } catch (IOException exc) {
        String msg = mLocalizer.msg("error.3", "Loading settings for plugin {0} failed!\n({1})",
            service.getInfo().getName(), f.getAbsolutePath(), exc);
        ErrorHandler.handle(msg, exc);
View Full Code Here

          }
        }
      }

      synchronized (inputLock) {
        bis = new BufferedInputStream(sock.getInputStream());
      }

      setStatus(CONNECT);
    } catch (IOException exc) {
      if (logger.isLoggable(BasicLevel.DEBUG))
View Full Code Here

    private String putData(InputStream srcStream, String remoteFile,
                           boolean append)
        throws IOException, FTPException {

        IOException storedEx = null;
        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        long size = 0;
        try {
            in = new BufferedInputStream(srcStream);
   
            remoteFile = initPut(remoteFile, append);
   
            // get an output stream
            out = new BufferedOutputStream(
                    new DataOutputStream(getOutputStream()), transferBufferSize*2);
           
            // if resuming, we skip over the unwanted bytes
            if (resume && resumeMarker > 0) {
                in.skip(resumeMarker);
            }
            else
                resumeMarker = 0;
   
            byte[] buf = new byte[transferBufferSize];
            byte[] prevBuf = new byte[FTP_LINE_SEPARATOR.length];
            int matchpos = 0;
   
            // read a chunk at a time and write to the data socket           
            long monitorCount = 0;
            int count = 0;
            boolean isASCII = getType() == FTPTransferType.ASCII;
            long start = System.currentTimeMillis();
            if (throttler != null) {
                throttler.reset();
            }
           
            while ((count = in.read(buf)) > 0 && !cancelTransfer) {
                if (isASCII) { // we want to allow \r\n, \r and \n
                    for (int i = 0; i < count; i++) {
                        // LF without preceding CR (i.e. Unix text file)
                        if (buf[i] == LINE_FEED && matchpos == 0) {
                            out.write(CARRIAGE_RETURN);
                            out.write(LINE_FEED);
                            size += 2;
                            monitorCount += 2;
                        }
                        else if (buf[i] == FTP_LINE_SEPARATOR[matchpos]) {
                            prevBuf[matchpos] = buf[i];
                            matchpos++;
                            if (matchpos == FTP_LINE_SEPARATOR.length) {
                                out.write(CARRIAGE_RETURN);
                                out.write(LINE_FEED);
                                size += 2;
                                monitorCount += 2;
                                matchpos = 0;
                            }
                        }
                        else { // no match current char
                            // this must be a matching \r if we matched first char
                            if (matchpos > 0) {
                                out.write(CARRIAGE_RETURN);
                                out.write(LINE_FEED);
                                size += 2;
                                monitorCount += 2;
                            }
                            out.write(buf[i]);
                            size++;
                            monitorCount++;
                            matchpos = 0;
                        }                             
                    }
                }
                else { // binary
                    out.write(buf, 0, count);
                    size += count;
                    monitorCount += count;
                }
               
                if (throttler != null) {
                    throttler.throttleTransfer(size);
                }
                                   
                if (monitor != null && monitorCount > monitorInterval) {
                    monitor.bytesTransferred(size);
                    monitorCount = 0
                }
                if (serverWakeupInterval > 0 && System.currentTimeMillis() - start > serverWakeupInterval*1000) {
                    start = System.currentTimeMillis();
                    sendServerWakeup();
                }
            }
            // write out anything left at the end that has been saved
            // - must be a \r which we convert into a line terminator
            if (isASCII && matchpos > 0) {
                out.write(CARRIAGE_RETURN);
                out.write(LINE_FEED);
                size += 2;
                monitorCount += 2;
            }
        }
        catch (IOException ex) {
            storedEx = ex;
            log.error("Caught and rethrowing exception in getDataAfterInitGet()", ex);
        }
        finally {
            resume = false;
            try {
                if (in != null)
                    in.close();
            }
            catch (IOException ex) {
                log.warn("Caught exception closing input stream", ex);
            }
               
View Full Code Here

        // create the buffered output stream for writing the file
        BufferedOutputStream out =
            new BufferedOutputStream(destStream);
       
        BufferedInputStream in = null;
        long size = 0;
        IOException storedEx = null;
        try {
            // get an input stream to read data from ... AFTER we have
            // the ok to go ahead AND AFTER we've successfully opened a
            // stream for the local file
            in = new BufferedInputStream(
                    new DataInputStream(getInputStream()));
       
            // do the retrieving
            long monitorCount = 0;
            byte [] chunk = new byte[transferBufferSize];
View Full Code Here

     @param file2  second file object
     */
    protected void assertIdentical(File file1, File file2)
        throws Exception {

        BufferedInputStream is1 = null;
        BufferedInputStream is2 = null;
        try {
            // check lengths first
            assertEquals(file1.length(), file2.length());
            log.debug("Identical size [" + file1.getName() +
                        "," + file2.getName() + "]");

            // now check each byte
            is1 = new BufferedInputStream(new FileInputStream(file1));
            is2 = new BufferedInputStream(new FileInputStream(file2));
            int ch1 = 0;
            int ch2 = 0;
            int count = 0;
            try {
                while ((ch1 = is1.read()) != -1 &&
                       (ch2 = is2.read()) != -1) {
                    count++;
                    assertEquals(ch1, ch2);
                }   
            }
            catch (AssertionFailedError e) {
                log.debug("Comparison failed on char position=" + count);
                throw e;
            }
            log.debug("Contents equal");
        }
        catch (IOException ex) {
            fail("Caught exception: " + ex.getMessage());
        }
        finally {
            if (is1 != null)
                is1.close();
            if (is2 != null)
                is2.close();
        }
    }
View Full Code Here

      if (xml.substring(xml.length() - 3, xml.length()).equals("xml"))
      {
        returnDocument = builder.parse(new File(filePath + xml));
      } else
      {
        InputStream in = new BufferedInputStream(new StringBufferInputStream(xml));
        returnDocument = builder.parse(in);
      }
    } catch (IOException e)
    {
      logger.error("[getDocumentFromString] Exception thrown.", e);
View Full Code Here

            Transformer transformer = null;
            InputStream xslStream = null;

            try {
                InputStream in = XSLTransformation.class.getResourceAsStream( stylesheet );
                xslStream = new BufferedInputStream( in );
                StreamSource src = new StreamSource( xslStream );
                src.setSystemId( stylesheet );
                transformer = TransformerFactory.newInstance().newTransformer( src );
            } finally {
                if ( xslStream != null ) xslStream.close();
View Full Code Here

TOP

Related Classes of java.io.BufferedInputStream

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.