Examples of BufferedOutputStream


Examples of java.io.BufferedOutputStream

      File tempFile = File.createTempFile("weka", SerializedInstancesLoader.FILE_EXTENSION);
      tempFile.deleteOnExit();

      ObjectOutputStream oos =
  new ObjectOutputStream(
  new BufferedOutputStream(
  new FileOutputStream(tempFile)));
   
      oos.writeObject(m_Instances);
      oos.flush();
      oos.close();
View Full Code Here

Examples of java.io.BufferedOutputStream

          }
          v.trimToSize();
          XStream.write(saveTo.getAbsolutePath(), v); */
        } else /* binary */ {
          ObjectOutputStream os =
            new ObjectOutputStream(new BufferedOutputStream(
                                   new FileOutputStream(saveTo)));
          os.writeObject(m_Classifier);
          if (m_trainingSet != null) {
            Instances header = new Instances(m_trainingSet, 0);
            os.writeObject(header);
View Full Code Here

Examples of java.io.BufferedOutputStream

            // 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
            out =
                new BufferedOutputStream(
                        new DataOutputStream(client.getOutputStream()), client.getTransferBufferSize()*2);

        }
        catch (IOException ex) {
            client.validateTransferOnError(ex);
View Full Code Here

Examples of java.io.BufferedOutputStream

* @param os  The <CODE>OutputStream</CODE> the writer has to write to.
*/

    protected DocWriter(Document document, OutputStream os)  {
        this.document = document;
        this.os = new OutputStreamCounter(new BufferedOutputStream(os));
    }
View Full Code Here

Examples of java.io.BufferedOutputStream

                           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) {
View Full Code Here

Examples of java.io.BufferedOutputStream

     */
    private void getDataAfterInitGet(OutputStream destStream)
        throws IOException, FTPException {

        // 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];
            int count;
            boolean isASCII = getType() == FTPTransferType.ASCII;
            long start = System.currentTimeMillis();
            if (throttler != null) {
                throttler.reset();
            }

            byte[] prevBuf = new byte[FTP_LINE_SEPARATOR.length];
            int matchpos = 0;

            // read from socket & write to file in chunks       
            while ((count = readChunk(in, chunk, transferBufferSize)) >= 0 && !cancelTransfer) {
                if (isASCII) {
                    for (int i = 0; i < count; i++) {
                        if (chunk[i] == FTP_LINE_SEPARATOR[matchpos]) {
                            prevBuf[matchpos] = chunk[i];
                            matchpos++;
                            if (matchpos == FTP_LINE_SEPARATOR.length) {
                                out.write(LINE_SEPARATOR);
                                size += LINE_SEPARATOR.length;
                                monitorCount += LINE_SEPARATOR.length;
                                matchpos = 0;
                            }
                        }
                        else { // no match
                            // write out existing matches
                            if (matchpos > 0) {
                                out.write(prevBuf, 0, matchpos);
                                size += matchpos;
                                monitorCount += matchpos;
                            }
                            out.write(chunk[i]);
                            size++;
                            monitorCount++;
                            matchpos = 0;
                        }                             
                    }               
                }
                else { // binary
                    out.write(chunk, 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
            if (isASCII && matchpos > 0) {
                out.write(prevBuf, 0, matchpos);
                size += matchpos;
                monitorCount += matchpos;
            }
        }
        catch (IOException ex) {
            storedEx = ex;
            log.error("Caught and rethrowing exception in getDataAfterInitGet()", ex);
        }
        finally {
            try {
                if (out != null)
                    out.close();
            }
            catch (IOException ex) {
                log.warn("Caught exception closing output stream", ex);
            }

View Full Code Here

Examples of java.io.BufferedOutputStream

              }
            };
          }
         
        });
            this.stream = new BufferedOutputStream(new FileOutputStream(f));
          }
          if (buffer.length == 0) {
            stream.close();
            stream = null;
            streamIndex++;
View Full Code Here

Examples of java.io.BufferedOutputStream

    }

    public static void write(final InputStream is, final File f) throws IOException {
      f.getParentFile().mkdirs();
        FileOutputStream fio = new FileOutputStream(f);
        BufferedOutputStream bos = new BufferedOutputStream(fio);
      write(bos, is, -1);
    }
View Full Code Here

Examples of java.io.BufferedOutputStream

    if (parentDir !=null) {
      parentDir.mkdirs();
    }

    FileOutputStream fio = null;
    BufferedOutputStream bos = null;
        try {
            fio = new FileOutputStream(f);
            bos = new BufferedOutputStream(fio);
            if (bufferSize > 0) {
            byte[] buff = new byte[bufferSize];
            int bytesRead;
       
            // Simple read/write loop.
            while(-1 != (bytesRead = is.read(buff, 0, buff.length))) {
              bos.write(buff, 0, bytesRead);
            }
            }
            bos.flush();
        } finally {
            if (bos != null) {
                bos.close();
            }
            if (fio != null) {
                fio.close();
            }
        }
View Full Code Here

Examples of java.io.BufferedOutputStream

    /**
     * Get a <code>BufferedOutputStream</code>.
     */
    public final static BufferedOutputStream getBufferedOutputStream(
            OutputStream out) {
        BufferedOutputStream bout = null;
        if (out instanceof java.io.BufferedOutputStream) {
            bout = (BufferedOutputStream) out;
        } else {
            bout = new BufferedOutputStream(out);
        }
        return bout;
    }
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.