Examples of BufferedOutputStream


Examples of java.io.BufferedOutputStream

        boolean isAscii = session.getDataType() == DataType.ASCII;
        long startTime = System.currentTimeMillis();
        byte[] buff = new byte[4096];

        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            bis = IoUtils.getBufferedInputStream(in);

            bos = IoUtils.getBufferedOutputStream(out);

            DefaultFtpSession defaultFtpSession = null;
            if (session instanceof DefaultFtpSession) {
                defaultFtpSession = (DefaultFtpSession) session;
            }

            byte lastByte = 0;
            while (true) {

                // if current rate exceeds the max rate, sleep for 50ms
                // and again check the current transfer rate
                if (maxRate > 0) {

                    // prevent "divide by zero" exception
                    long interval = System.currentTimeMillis() - startTime;
                    if (interval == 0) {
                        interval = 1;
                    }

                    // check current rate
                    long currRate = (transferredSize * 1000L) / interval;
                    if (currRate > maxRate) {
                        try {
                            Thread.sleep(50);
                        } catch (InterruptedException ex) {
                            break;
                        }
                        continue;
                    }
                }

                // read data
                int count = bis.read(buff);

                if (count == -1) {
                    break;
                }

                // update MINA session
                if (defaultFtpSession != null) {
                    if (isWrite) {
                        defaultFtpSession.increaseWrittenDataBytes(count);
                    } else {
                        defaultFtpSession.increaseReadDataBytes(count);
                    }
                }

                // write data
                // if ascii, replace \n by \r\n
                if (isAscii) {
                    for (int i = 0; i < count; ++i) {
                        byte b = buff[i];
                        if(isWrite) {
                            if (b == '\n' && lastByte != '\r') {
                                bos.write('\r');
                            }
   
                            bos.write(b);
                        } else {
                            if(b == '\n') {
                                // for reads, we should always get \r\n
                                // so what we do here is to ignore \n bytes
                                // and on \r dump the system local line ending.
                                // Some clients won't transform new lines into \r\n so we make sure we don't delete new lines
                                if (lastByte != '\r'){
                                    bos.write(EOL);
                                }
                            } else if(b == '\r') {
                                bos.write(EOL);
                            } else {
                                // not a line ending, just output
                                bos.write(b);
                            }
                        }
                        // store this byte so that we can compare it for line endings
                        lastByte = b;
                    }
                } else {
                    bos.write(buff, 0, count);
                }

                transferredSize += count;

                notifyObserver();
            }
        } catch(IOException e) {
            LOG.warn("Exception during data transfer, closing data connection socket", e);
            factory.closeDataConnection();
            throw e;
        } catch(RuntimeException e) {
            LOG.warn("Exception during data transfer, closing data connection socket", e);
            factory.closeDataConnection();
            throw e;
        } finally {
            if (bos != null) {
                bos.flush();
            }
        }

        return transferredSize;
    }
View Full Code Here

Examples of java.io.BufferedOutputStream

  {
    UserManagerConfig config = new UserManagerConfig();
    List users = new ArrayList( usersMap.values() );
    config.setUsers(users);
   
    XMLEncoder encoder = new XMLEncoder( new BufferedOutputStream( out ) );
    encoder.writeObject(config);
    encoder.close();
  }
View Full Code Here

Examples of java.io.BufferedOutputStream

        basePath = new File(basePath).getPath();
        try {
            if (new File(destFile).isDirectory()) {
                throw new IOException("Can't create the file as a directory with this name already exists: " + destFile);
            }
            OutputStream out = new BufferedOutputStream(new FileOutputStream(destFile));
            ZipOutputStream zipOut;
            if (jar) {
                zipOut = new JarOutputStream(out);
            } else {
                zipOut = new ZipOutputStream(out);
View Full Code Here

Examples of java.io.BufferedOutputStream

      String[] names = file.list();
      if (names == null) {
        res.sendError(HttpServletResponse.SC_FORBIDDEN, "Can't access " + req.getRequestURI());
        return;
      }
      PrintStream p = new PrintStream(new BufferedOutputStream(out), false, charSet); // 1.4
      p.println("<HTML><HEAD>");
      p.println("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=" + charSet + "\">");
      p.println("<TITLE>Index of " + path + "</TITLE>");
      p.println("</HEAD><BODY " + Serve.BGCOLOR);
      p.println("><H2>Index of " + path + "</H2>");
View Full Code Here

Examples of java.io.BufferedOutputStream

          response.setContentType(this.getMimeType(fileName));
        }
       
        // send the output.
        ServletOutputStream outStream = response.getOutputStream();
        BufferedOutputStream bufferedOutStream = new BufferedOutputStream(outStream);
        bufferedOutStream.write(buffer, 0, buffer.length);
        bufferedOutStream.flush();
        bufferedOutStream.close();
      }//end of if(fileID > 0)
    }
    catch(Exception e){
      logger.error("[ImageServlet] Exception thrown in service(): ", e);
    }
View Full Code Here

Examples of java.io.BufferedOutputStream

      response.setContentType("image/gif");
      buffer = spacerGif;
    }
    // send the output.
    ServletOutputStream outStream = response.getOutputStream();
    BufferedOutputStream bufferedOutStream = new BufferedOutputStream(outStream);
    bufferedOutStream.write(buffer, 0, buffer.length);
    bufferedOutStream.flush();
    bufferedOutStream.close();
  }
View Full Code Here

Examples of java.io.BufferedOutputStream

                lobManager.updateReferences(batchManager.lobIndexes, tuple);
              }
            }
            synchronized (batchManager.store) {
              offset = batchManager.getOffset();
              OutputStream fsos = new BufferedOutputStream(batchManager.store.createOutputStream(), IO_BUFFER_SIZE);
                    ObjectOutputStream oos = new ObjectOutputStream(fsos);
                    batch.writeExternal(oos);
                    oos.close();
                    long size = batchManager.store.getLength() - offset;
                    long[] info = new long[] {offset, size};
View Full Code Here

Examples of java.io.BufferedOutputStream

    private Object readLock = new Object();

    private OioObjectChannel(Socket socket) throws IOException {
      log.fine("creating new OioObjectChannel"); //$NON-NLS-1$
      this.socket = socket;
            BufferedOutputStream bos = new BufferedOutputStream( socket.getOutputStream(), STREAM_BUFFER_SIZE);
            outputStream = new ObjectEncoderOutputStream( new DataOutputStream(bos), 512);
            //The output stream must be flushed on creation in order to write some initialization data
            //through the buffered stream to the input stream on the other side
            outputStream.flush();
            final ClassLoader cl = this.getClass().getClassLoader();
View Full Code Here

Examples of java.io.BufferedOutputStream

    private static PrintStream getSummaryStream(String outputDir,
      String summaryName) throws IOException {
  File summaryFile = createSummaryFile(outputDir, summaryName);
  OutputStream os = new FileOutputStream(summaryFile);
  os = new BufferedOutputStream(os);
  return new PrintStream(os);
    }
View Full Code Here

Examples of java.io.BufferedOutputStream

        + summaryFile.getAbsolutePath());
      throw ioe;
  }

  OutputStream os = new FileOutputStream(summaryFile);
  os = new BufferedOutputStream(os);
  return new PrintStream(os);
    }
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.