List of usage examples for java.io BufferedOutputStream BufferedOutputStream
public BufferedOutputStream(OutputStream out)
From source file:com.baasbox.util.Util.java
public static void createZipFile(String path, File... files) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("Zipping into:" + path); ZipOutputStream zip = null;//from ww w . ja va 2 s. co m FileOutputStream dest = null; try { File f = new File(path); dest = new FileOutputStream(f); zip = new ZipOutputStream(new BufferedOutputStream(dest)); for (File file : files) { zip.putNextEntry(new ZipEntry(file.getName())); zip.write(FileUtils.readFileToByteArray(file)); zip.closeEntry(); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Unable to create zip file"); } finally { try { if (zip != null) zip.close(); if (dest != null) dest.close(); } catch (Exception ioe) { //Nothing to do } } }
From source file:com.shigeodayo.ardrone.utils.ARDroneInfo.java
private boolean connectToDroneThroughFtp() { FTPClient client = new FTPClient(); BufferedOutputStream bos = null; try {/* ww w. j av a2 s. c om*/ client.connect(ARDroneConstants.IP_ADDRESS, ARDroneConstants.FTP_PORT); if (!client.login("anonymous", "")) { ARDrone.error("Login failed", this); return false; } client.setFileType(FTP.BINARY_FILE_TYPE); bos = new BufferedOutputStream(new OutputStream() { @Override public void write(int arg0) throws IOException { //System.out.println("aa:" + (char)arg0); switch (count) { case 0: major = arg0 - '0'; break; case 2: minor = arg0 - '0'; break; case 4: revision = arg0 - '0'; break; default: break; } count++; } }); if (!client.retrieveFile("/" + VERSION_FILE_NAME, bos)) { ARDrone.error("Cannot find \"" + VERSION_FILE_NAME + "\"", this); return false; } bos.flush(); //System.out.print("major:" + major); //System.out.print(" minor:" + minor); //System.out.println(" revision:" + revision); //System.out.println("done"); } catch (IOException e) { e.printStackTrace(); return false; } finally { try { if (bos != null) { bos.flush(); bos.close(); } client.disconnect(); } catch (IOException e) { e.printStackTrace(); return false; } } return true; }
From source file:eu.scape_project.spacip.ContainerProcessing.java
/** * Write ARC record content to output stream * * @param nativeArchiveRecord/*w ww .j a v a2s . com*/ * @param outputStream Output stream * @throws IOException */ public static void recordToOutputStream(ArchiveRecord nativeArchiveRecord, OutputStream outputStream) throws IOException { ARCRecord arcRecord = (ARCRecord) nativeArchiveRecord; ARCRecordMetaData metaData = arcRecord.getMetaData(); long contentBegin = metaData.getContentBegin(); BufferedInputStream bis = new BufferedInputStream(arcRecord); BufferedOutputStream bos = new BufferedOutputStream(outputStream); byte[] tempBuffer = new byte[BUFFER_SIZE]; int bytesRead; // skip record header bis.skip(contentBegin); while ((bytesRead = bis.read(tempBuffer)) != -1) { bos.write(tempBuffer, 0, bytesRead); } bos.flush(); bis.close(); bos.close(); }
From source file:cn.ict.zyq.bestConf.cluster.Utils.RemoteFileAccess.java
public void download(SFtpConnectInfo connectInfo, String localPath, final String remotePath) { JSch jsch = new JSch(); Session session = null;// www .j a v a2 s . c om ChannelSftp channel = null; OutputStream outs = null; try { session = jsch.getSession(connectInfo.getUsername(), connectInfo.getHost(), connectInfo.getPort()); session.setPassword(connectInfo.getPassword()); Properties props = new Properties(); props.put("StrictHostKeyChecking", "no"); session.setConfig(props); session.connect(5000); channel = (ChannelSftp) session.openChannel("sftp"); channel.connect(5000); outs = new BufferedOutputStream(new FileOutputStream(new File(localPath))); channel.get(remotePath, outs, new SftpProgressMonitor() { private long current = 0; @Override public void init(int op, String src, String dest, long max) { } @Override public void end() { } @Override public boolean count(long count) { current += count; return true; } }); } catch (JSchException e) { System.err.println(String.format( "connect remote host[%s:%d] occurs error " + connectInfo.getHost() + +connectInfo.getPort())); e.printStackTrace(); } catch (SftpException e) { System.err.println(String.format("get remote file:%s occurs error", remotePath)); e.printStackTrace(); } catch (FileNotFoundException e) { System.err.println(String.format("can not find local file:%s", localPath)); e.printStackTrace(); } finally { IOUtils.closeQuietly(outs); if (null != channel) { channel.disconnect(); } if (null != session) { session.disconnect(); } } }
From source file:org.pegadi.webapp.view.FileView.java
protected void renderMergedOutputModel(Map map, HttpServletRequest request, HttpServletResponse response) throws IOException { // get the file from the map File file = (File) map.get("file"); // check if it exists if (file == null || !file.exists() || !file.canRead()) { log.warn("Error reading: " + file); try {//w w w . j ava 2s . c om response.sendError(404); } catch (IOException e) { log.error("Could not write to response", e); } return; } // give some info in the response response.setContentType(getServletContext().getMimeType(file.getAbsolutePath())); // files does not change so often, allow three days caching response.setHeader("Cache-Control", "max-age=259200"); response.setContentLength((int) file.length()); // start writing to the response BufferedOutputStream out = null; BufferedInputStream in = null; try { out = new BufferedOutputStream(response.getOutputStream()); in = new BufferedInputStream(new FileInputStream(file)); int c = in.read(); while (c != -1) { out.write(c); c = in.read(); } } finally { if (in != null) { in.close(); } if (out != null) { out.flush(); out.close(); } } }
From source file:com.l2jfree.network.NetworkThread.java
protected final void initConnection(Socket con) throws IOException { _connection = con;// w ww. j av a 2 s . c om _connectionIp = con.getInetAddress().getHostAddress(); _in = new BufferedInputStream(con.getInputStream()); _out = new BufferedOutputStream(con.getOutputStream()); _blowfish = new NewCrypt("_;v.]05-31!|+-%xT!^[$\00"); }
From source file:org.apache.qpid.disttest.charting.writer.ChartWriter.java
public void writeChartToFileSystem(JFreeChart chart, ChartingDefinition chartDef) { OutputStream pngOutputStream = null; try {// www . j a v a2s. c om File pngFile = new File(_chartDirectory, chartDef.getChartStemName() + ".png"); pngOutputStream = new BufferedOutputStream(new FileOutputStream(pngFile)); ChartUtilities.writeChartAsPNG(pngOutputStream, chart, 600, 400, true, 0); pngOutputStream.close(); _chartFilesToChartDef.put(pngFile, chartDef); LOGGER.info("Written {} chart", pngFile); } catch (IOException e) { throw new ChartingException("Failed to create chart", e); } finally { if (pngOutputStream != null) { try { pngOutputStream.close(); } catch (IOException e) { throw new ChartingException("Failed to create chart", e); } } } }
From source file:de.innovationgate.utils.XStreamUtils.java
/** * Serializes an object to a UTF-8 encoded output stream * @param obj The object to write//w ww.j a va 2 s . c o m * @param xstream The XStream instance to use * @param out The output stream to write to * @throws IOException */ public static void writeUtf8ToOutputStream(Object obj, XStream xstream, OutputStream out) throws IOException { BufferedOutputStream bufOut = new BufferedOutputStream(out); OutputStreamWriter writer; try { writer = new OutputStreamWriter(bufOut, "UTF-8"); xstream.toXML(obj, writer); writer.flush(); writer.close(); } catch (UnsupportedEncodingException e) { // Cannot happen since Java always supports UTF-8 } }
From source file:com.opengamma.web.analytics.json.Compressor.java
static void compressStream(InputStream inputStream, OutputStream outputStream) throws IOException { InputStream iStream = new BufferedInputStream(inputStream); GZIPOutputStream oStream = new GZIPOutputStream( new Base64OutputStream(new BufferedOutputStream(outputStream), true, -1, null), 2048); byte[] buffer = new byte[2048]; int bytesRead; while ((bytesRead = iStream.read(buffer)) != -1) { oStream.write(buffer, 0, bytesRead); }//from w w w . ja v a 2s . co m oStream.close(); // this is necessary for the gzip and base64 streams }
From source file:org.slc.sli.ingestion.IngestionTest.java
public static OutputStream createTempFileOutputStream() throws IOException { File file = createTempFile(); return new BufferedOutputStream(new FileOutputStream(file)); }