public void testWriteFrom_inputStream() throws IOException { sink.writeFrom(new ByteArrayInputStream(data)); assertContainsExpectedBytes(); }
Files.asByteSink(outFile).writeFrom(inputStream); mCopied++; } catch (FileNotFoundException e) {
/** * Opens an output stream from the supplier, copies all bytes from the input * to the output, and closes the output stream. Does not close or flush the * input stream. * * @param from the input stream to read from * @param to the output factory * @return the number of bytes copied * @throws IOException if an I/O error occurs * @since 10.0 */ public static long copy(InputStream from, OutputSupplier<? extends OutputStream> to) throws IOException { return asByteSink(to).writeFrom(from); }
/** * Opens an output stream from the supplier, copies all bytes from the input * to the output, and closes the output stream. Does not close or flush the * input stream. * * @param from the input stream to read from * @param to the output factory * @return the number of bytes copied * @throws IOException if an I/O error occurs * @since 10.0 */ public static long copy(InputStream from, OutputSupplier<? extends OutputStream> to) throws IOException { return asByteSink(to).writeFrom(from); }
/** * Opens an output stream from the supplier, copies all bytes from the input * to the output, and closes the output stream. Does not close or flush the * input stream. * * @param from the input stream to read from * @param to the output factory * @return the number of bytes copied * @throws IOException if an I/O error occurs * @since 10.0 */ public static long copy(InputStream from, OutputSupplier<? extends OutputStream> to) throws IOException { return asByteSink(to).writeFrom(from); }
/** * Opens an output stream from the supplier, copies all bytes from the input * to the output, and closes the output stream. Does not close or flush the * input stream. * * @param from the input stream to read from * @param to the output factory * @return the number of bytes copied * @throws IOException if an I/O error occurs * @since 10.0 */ public static long copy(InputStream from, OutputSupplier<? extends OutputStream> to) throws IOException { return asByteSink(to).writeFrom(from); }
/** * Opens an output stream from the supplier, copies all bytes from the input * to the output, and closes the output stream. Does not close or flush the * input stream. * * @param from the input stream to read from * @param to the output factory * @return the number of bytes copied * @throws IOException if an I/O error occurs * @since 10.0 */ public static long copy(InputStream from, OutputSupplier<? extends OutputStream> to) throws IOException { return asByteSink(to).writeFrom(from); }
private static void extractSources(File tempDir, File inJar) throws IOException { try (ZipInputStream zin = new ZipInputStream(new FileInputStream(inJar))) { ZipEntry entry; while ((entry = zin.getNextEntry()) != null) { // we dont care about directories.. we can make em later when needed // we only want java files to compile too, can grab the other resources from the jar later if (entry.isDirectory() || !entry.getName().endsWith(".java")) continue; File out = new File(tempDir, entry.getName()); out.getParentFile().mkdirs(); Files.asByteSink(out).writeFrom(zin); } } }
/** * Opens an output stream from the supplier, copies all bytes from the input * to the output, and closes the output stream. Does not close or flush the * input stream. * * @param from the input stream to read from * @param to the output factory * @return the number of bytes copied * @throws IOException if an I/O error occurs * @since 10.0 * @deprecated Use {@link ByteSink#writeFrom(InputStream)} instead. This * method is scheduled for removal in Guava 18.0. */ @Deprecated public static long copy(InputStream from, OutputSupplier<? extends OutputStream> to) throws IOException { return asByteSink(to).writeFrom(from); }
/** * Opens an output stream from the supplier, copies all bytes from the input * to the output, and closes the output stream. Does not close or flush the * input stream. * * @param from the input stream to read from * @param to the output factory * @return the number of bytes copied * @throws IOException if an I/O error occurs * @since 10.0 * @deprecated Use {@link ByteSink#writeFrom(InputStream)} instead. This * method is scheduled for removal in Guava 18.0. */ @Deprecated public static long copy(InputStream from, OutputSupplier<? extends OutputStream> to) throws IOException { return asByteSink(to).writeFrom(from); }
public File asFile(String message, File file) throws IOException { InputStream inputStream = toInputStream(message); try { Files.asByteSink(file).writeFrom(inputStream); } finally { inputStream.close(); } return file; }
@VisibleForTesting public static void extractBundledProguardFile( @NonNull String name, @NonNull File proguardFile) throws IOException { Files.createParentDirs(proguardFile); URL proguardURL = ProguardFiles.class.getResource(name); URLConnection urlConnection = proguardURL.openConnection(); urlConnection.setUseCaches(false); try (InputStream is = urlConnection.getInputStream()) { Files.asByteSink(proguardFile).writeFrom(is); } } }
@Override public UploadedFile saveAndGet() throws UploadRequestException { InputStream input = null; try { input = file.openStream(); File tempFile = File.createTempFile("uploaded-file-", ".tmp"); Files.asByteSink(tempFile).writeFrom(input); return new UploadedFileTemp(tempFile, file); } catch (IOException e) { throw new UploadRequestException(e); } finally { if (input != null) { try { input.close(); } catch (IOException e) { } } } }
public void testWriteFrom_inputStream() throws IOException { sink.writeFrom(new ByteArrayInputStream(data)); assertContainsExpectedBytes(); }
@Override public UploadedFile saveAndGet() throws UploadRequestException { InputStream input = null; try { input = file.openStream(); File tempFile = File.createTempFile("uploaded-file-", ".tmp"); Files.asByteSink(tempFile).writeFrom(input); return new UploadedFileTemp(tempFile, file); } catch (IOException e) { throw new UploadRequestException(e); } finally { if (input != null) { try { input.close(); } catch (IOException e) { } } } }
/** * Unzips the input stream via a gzip filter. use gunzip(ByteSource, File, Predicate) if possible * * @param in The input stream to run through the gunzip filter. This stream is closed * @param outFile The file to output to * * @throws IOException */ public static FileUtils.FileCopyResult gunzip(InputStream in, File outFile) throws IOException { try (GZIPInputStream gzipInputStream = gzipInputStream(in)) { Files.asByteSink(outFile).writeFrom(gzipInputStream); return new FileUtils.FileCopyResult(outFile); } }
static AndSaveTo executeFile(UploadCtx ctx, UploadedFile uploadedFile, File target) { Preconditions.checkArgument(!target.isDirectory(), "file cannot be a directory"); InputStream is = null; try { is = uploadedFile.openStream(); Files.asByteSink(target).writeFrom(is); return new AndSaveToValid(ctx, target); } catch (UploadRequestException e) { return new AndSaveToInvalid(ctx, e); } catch (IOException e) { return new AndSaveToInvalid(ctx, e); } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } }
/** * Unzips the input stream via a gzip filter. use gunzip(ByteSource, File, Predicate) if possible * * @param in The input stream to run through the gunzip filter. This stream is closed * @param outFile The file to output to * * @throws IOException */ public static FileUtils.FileCopyResult gunzip(InputStream in, File outFile) throws IOException { try (GZIPInputStream gzipInputStream = gzipInputStream(in)) { Files.asByteSink(outFile).writeFrom(gzipInputStream); return new FileUtils.FileCopyResult(outFile); } }
/** * Unzips the input stream via a gzip filter. use gunzip(ByteSource, File, Predicate) if possible * * @param in The input stream to run through the gunzip filter. This stream is closed * @param outFile The file to output to * * @throws IOException */ public static FileUtils.FileCopyResult gunzip(InputStream in, File outFile) throws IOException { try (GZIPInputStream gzipInputStream = gzipInputStream(in)) { Files.asByteSink(outFile).writeFrom(gzipInputStream); return new FileUtils.FileCopyResult(outFile); } }
@Override public void write(String fileName) throws IOException { checkNotDeleted(); Files.asByteSink(getOutputFile(fileName)).writeFrom(getInputStream()); }