APISonar


com.google.common.io.Files.asByteSink

> com > google > common > io > Files > asByteSink
com APIs google APIs common APIs io APIs Files APIs asByteSink APIs

Example 1
private static void tryCopyIfNeeded(ByteSource supplier, File rcFile) {
    if (!rcFile.exists()) {
      try {
        supplier.copyTo(Files.asByteSink(rcFile));
      } catch (IOException e) {
        rcFile.delete();
      }
    }
  }
Example 2
public int execute(ExecutionContext context) {
    try {
      source.copyTo(
          Files.asByteSink(context.getProjectFilesystem().resolve(outputPath).toFile()));
      return 0;
    } catch (IOException e) {
      e.printStackTrace(context.getStdErr());
      return 1;
    }
  }
Example 3
private synchronized void installExtension(ByteSource extensionSrc, File targetFile)
      throws IOException {
    if (targetFile.exists()) {
      backup.backup(targetFile);
    }
    extensionSrc.copyTo(Files.asByteSink(targetFile));
    installedExtensions.add(targetFile);
  }
Example 4
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);
    }
  }
Example 5
private void runEncrypt() throws IOException {
    boolean isOutputToDir = output.toFile().isDirectory();
    Path outFile = isOutputToDir ? output.resolve(input.getFileName() + ".ghostryde") : output;
    Path lenOutFile = isOutputToDir ? output.resolve(input.getFileName() + ".length") : null;
    try (OutputStream out = Files.asByteSink(outFile.toFile()).openBufferedStream();
        OutputStream lenOut =
            (lenOutFile == null)
                ? null
                : Files.asByteSink(lenOutFile.toFile()).openBufferedStream();
        OutputStream ghostrydeEncoder =
            Ghostryde.encoder(out, rdeStagingEncryptionKey.get(), lenOut);
        InputStream in = Files.asByteSource(input.toFile()).openBufferedStream()) {
      ByteStreams.copy(in, ghostrydeEncoder);
    }
  }
Example 6
public static FileUtils.FileCopyResult unzip(InputStream in, File outDir) throws IOException
  {
    try (final ZipInputStream zipIn = new ZipInputStream(in)) {
      final FileUtils.FileCopyResult result = new FileUtils.FileCopyResult();
      ZipEntry entry;
      while ((entry = zipIn.getNextEntry()) != null) {
        final File file = new File(outDir, entry.getName());
        Files.asByteSink(file).writeFrom(zipIn);
        result.addFile(file);
        zipIn.closeEntry();
      }
      return result;
    }
  }
Example 7
public void testFirstPushWinsForConcurrentPushes() throws IOException
  {
    File replicatedDataSegmentFiles = temporaryFolder.newFolder();
    Files.asByteSink(new File(replicatedDataSegmentFiles, "version.bin")).write(Ints.toByteArray(0x8));
    DataSegment returnSegment1 = localDataSegmentPusher.push(dataSegmentFiles, dataSegment);
    DataSegment returnSegment2 = localDataSegmentPusher.push(replicatedDataSegmentFiles, dataSegment);

    Assert.assertEquals(returnSegment1, returnSegment2);
  }
Example 8
public static FileUtils.FileCopyResult gzip(final File inFile, final File outFile, Predicate<Throwable> shouldRetry)
  {
    gzip(Files.asByteSource(inFile), Files.asByteSink(outFile), shouldRetry);
    return new FileUtils.FileCopyResult(outFile);
  }
Example 9
public void whenWriteUsingByteSink_thenWritten() throws IOException {
        final String expectedValue = "Hello world";
        final File file = new File("src/test/resources/test.out");
        final ByteSink sink = Files.asByteSink(file);

        sink.write(expectedValue.getBytes());

        final String result = Files.toString(file, Charsets.UTF_8);
        assertEquals(expectedValue, result);
    }
Example 10
private File generateSegmentDir() throws IOException
  {
    // Each file size is 138 bytes after compression
    final File segmentDir = temporaryFolder.newFolder();
    Files.asByteSink(new File(segmentDir, "version.bin")).write(Ints.toByteArray(0x9));
    FileUtils.write(new File(segmentDir, "test"), "test data.", StandardCharsets.UTF_8);
    return segmentDir;
  }