public ByteStreamGobbler(String name, InputStream is, OutputStream out) { super(name); this.inStream = new BufferedInputStream(is); this.outStream = new BufferedOutputStream(out); }
private void writeFile (File outFile, byte[] bytes) { OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(outFile)); out.write(bytes); } catch (IOException e) { throw new RuntimeException("Couldn't write file '" + outFile.getAbsolutePath() + "'", e); } finally { if (out != null) try { out.close(); } catch (IOException e) { } } }
public static <T> void serializeCounter(Counter<T> c, String filename) throws IOException { // serialize to file ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(filename))); out.writeObject(c); out.close(); }
public void saveTo(String file) throws IOException { File f = new File(file); File path = f.getParentFile(); if(!path.exists()){ path.mkdirs(); } ObjectOutputStream out = new ObjectOutputStream(new GZIPOutputStream( new BufferedOutputStream(new FileOutputStream(file)))); out.writeObject(this); out.close(); } /**
public static void jarDir(File dir, String relativePath, ZipOutputStream zos) throws IOException { Preconditions.checkNotNull(relativePath, "relativePath"); Preconditions.checkNotNull(zos, "zos"); // by JAR spec, if there is a manifest, it must be the first entry in // the // ZIP. File manifestFile = new File(dir, JarFile.MANIFEST_NAME); ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME); if (!manifestFile.exists()) { zos.putNextEntry(manifestEntry); new Manifest().write(new BufferedOutputStream(zos)); zos.closeEntry(); } else { InputStream is = new FileInputStream(manifestFile); copyToZipStream(is, manifestEntry, zos); } zos.closeEntry(); zipDir(dir, relativePath, zos, true); zos.close(); }
public static void redirectOutput(String file) throws Exception { System.out.println("Redirecting output to " + file); FileOutputStream workerOut = new FileOutputStream(new File(file)); PrintStream ps = new PrintStream(new BufferedOutputStream(workerOut), true); System.setOut(ps); System.setErr(ps); LOG.info("Successfully redirect System.out to " + file); }
public static void gzip(File source, File dest, boolean deleteSource) throws IOException { byte[] buffer = new byte[2^20]; GZIPOutputStream out = new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(dest), 65536)){{def.setLevel(Deflater.BEST_COMPRESSION);}}; FileInputStream in = new FileInputStream(source); int l; while ((l = in.read(buffer)) > 0) out.write(buffer, 0, l); in.close(); out.finish(); out.close(); if (deleteSource && dest.exists()) source.delete(); }
public boolean updateConsoleLog(File dest, InputStream in) { File parentFile = dest.getParentFile(); parentFile.mkdirs(); LOGGER.trace("Updating console log [{}]", dest.getAbsolutePath()); try (OutputStream out = new BufferedOutputStream(new FileOutputStream(dest, dest.exists()))) { IOUtils.copy(in, out); } catch (IOException e) { LOGGER.error("Failed to update console log at : [{}]", dest.getAbsolutePath(), e); return false; } LOGGER.trace("Console log [{}] saved.", dest.getAbsolutePath()); return true; }
/** * Gzip file. * * @param zipFileName * @param mDestFile * @throws Exception */ public static void gzips(String zipFileName, String mDestFile) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(zipFileName), "UTF-8")); BufferedOutputStream out = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(mDestFile))); int c; while ((c = in.read()) != -1) { out.write(String.valueOf((char) c).getBytes("UTF-8")); } in.close(); out.close(); }
protected DataOutputStream makeFileOutput(String directoryName) { String classname = getName(); String filename = directoryName + File.separatorChar + classname.replace('.', File.separatorChar) + ".class"; int pos = filename.lastIndexOf(File.separatorChar); if (pos > 0) { String dir = filename.substring(0, pos); if (!dir.equals(".")) new File(dir).mkdirs(); } return new DataOutputStream(new BufferedOutputStream( new DelayedFileOutputStream(filename))); }
private void copyImageToMemory(File outFile) { try { BufferedOutputStream os = new BufferedOutputStream( new FileOutputStream(outFile)); BufferedInputStream is = new BufferedInputStream(getResources() .openRawResource(R.raw.painter)); copy(is, os); } catch (FileNotFoundException e) { Log.e(TAG, "FileNotFoundException"); } }
static public void copyToStream(File src, OutputStream os) throws IOException { final InputStream fis = new BufferedInputStream(new FileInputStream(src)); final OutputStream fos = new BufferedOutputStream(os); copyInternal(fis, fos); }
final void process(Socket clnt) throws IOException { InputStream in = new BufferedInputStream(clnt.getInputStream()); String cmd = readLine(in); logging(clnt.getInetAddress().getHostName(), new Date().toString(), cmd); while (skipLine(in) > 0){ } OutputStream out = new BufferedOutputStream(clnt.getOutputStream()); try { doReply(in, out, cmd); } catch (BadHttpRequest e) { replyError(out, e); } out.flush(); in.close(); out.close(); clnt.close(); }
InputStream reader = new BufferedInputStream( object.getObjectContent()); File file = new File("localFilename"); OutputStream writer = new BufferedOutputStream(new FileOutputStream(file)); int read = -1; while ( ( read = reader.read() ) != -1 ) { writer.write(read); } writer.flush(); writer.close(); reader.close();
public void flush () { OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(file)); properties.storeToXML(out, null); } catch (Exception ex) { throw new RuntimeException("Error writing preferences: " + file, ex); } finally { if (out != null) try { out.close(); } catch (IOException e) { } } }
private void backupConfigRepository(File backupDir) throws IOException { File configRepoDir = systemEnvironment.getConfigRepoDir(); try (ZipOutputStream configRepoZipStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(new File(backupDir, CONFIG_REPOSITORY_BACKUP_ZIP))))) { new DirectoryStructureWalker(configRepoDir.getAbsolutePath(), configRepoZipStream).walk(); } }
/** * zip list of file * * @param resFileList file(dir) list * @param zipFile output zip file * @throws IOException */ public static void zipFiles(Collection<File> resFileList, File zipFile, String comment) throws IOException { ZipOutputStream zipout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile), TypedValue.BUFFER_SIZE)); for (File resFile : resFileList) { if (resFile.exists()) { zipFile(resFile, zipout, ""); } } if (comment != null) { zipout.setComment(comment); } zipout.close(); }
public static ObjectOutputStream writeStreamFromString(String serializePath) throws IOException { ObjectOutputStream oos; if (serializePath.endsWith(".gz")) { oos = new ObjectOutputStream(new BufferedOutputStream( new GZIPOutputStream(new FileOutputStream(serializePath)))); } else { oos = new ObjectOutputStream(new BufferedOutputStream( new FileOutputStream(serializePath))); } return oos; }
private void gzipFile(String srcPath, String destPath) throws Exception { byte[] buffer = new byte[1024]; FileOutputStream fileOutputStream = new FileOutputStream(destPath); DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new GZIPOutputStream(fileOutputStream))); FileInputStream fileInput = new FileInputStream(srcPath); int bytes_read; while((bytes_read = fileInput.read(buffer)) > 0) { out.write(buffer, 0, bytes_read); } fileInput.close(); out.close(); }
/** * Creates a tar ball. */ public WorkspaceSnapshot snapshot(AbstractBuild<?, ?> build, FilePath ws, String glob, TaskListener listener) throws IOException, InterruptedException { File wss = new File(build.getRootDir(),"workspace.tgz"); try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(wss.toPath()))) { ws.archive(ArchiverFactory.TARGZ, os, glob); } catch (InvalidPathException e) { throw new IOException(e); } return new WorkspaceSnapshotImpl(); }