Search in sources :

Example 61 with BufferedOutputStream

use of java.io.BufferedOutputStream in project bazel by bazelbuild.

the class AndroidResourceValidatorAction method unpackZip.

private static void unpackZip(Path mergedResources, Path expandedOut) throws IOException {
    byte[] buffer = new byte[4096];
    try (ZipInputStream zis = new ZipInputStream(new BufferedInputStream(Files.newInputStream(mergedResources)))) {
        ZipEntry z = zis.getNextEntry();
        while (z != null) {
            String entryName = z.getName();
            Path outputPath = expandedOut.resolve(entryName);
            Files.createDirectories(outputPath.getParent());
            try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(outputPath))) {
                int count = zis.read(buffer);
                while (count != -1) {
                    out.write(buffer, 0, count);
                    count = zis.read(buffer);
                }
            }
            z = zis.getNextEntry();
        }
    }
}
Also used : Path(java.nio.file.Path) ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipEntry(java.util.zip.ZipEntry) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 62 with BufferedOutputStream

use of java.io.BufferedOutputStream in project bazel by bazelbuild.

the class AndroidResourceOutputs method createSrcJar.

/** Creates a zip archive from all found R.java files. */
public static void createSrcJar(Path generatedSourcesRoot, Path srcJar, boolean staticIds) {
    try {
        Files.createDirectories(srcJar.getParent());
        try (final ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(srcJar)))) {
            SymbolFileSrcJarBuildingVisitor visitor = new SymbolFileSrcJarBuildingVisitor(zip, generatedSourcesRoot, staticIds);
            Files.walkFileTree(generatedSourcesRoot, visitor);
            visitor.writeEntries();
        }
        // Set to the epoch for caching purposes.
        Files.setLastModifiedTime(srcJar, FileTime.fromMillis(0L));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 63 with BufferedOutputStream

use of java.io.BufferedOutputStream in project bazel by bazelbuild.

the class AndroidResourceOutputs method createClassJar.

/** Creates a zip archive from all found R.class (and inner class) files. */
public static void createClassJar(Path generatedClassesRoot, Path classJar) {
    try {
        Files.createDirectories(classJar.getParent());
        try (final ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(classJar)))) {
            ClassJarBuildingVisitor visitor = new ClassJarBuildingVisitor(zip, generatedClassesRoot);
            Files.walkFileTree(generatedClassesRoot, visitor);
            visitor.writeEntries();
            visitor.writeManifestContent();
        }
        // Set to the epoch for caching purposes.
        Files.setLastModifiedTime(classJar, FileTime.fromMillis(0L));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 64 with BufferedOutputStream

use of java.io.BufferedOutputStream in project bazel by bazelbuild.

the class AndroidDataSerializer method flushTo.

/**
   * Writes all of the collected DataKey -> DataValue.
   *
   * The binary format will be: <pre>
   * {@link Header}
   * {@link com.google.devtools.build.android.proto.SerializeFormat.DataKey} keys...
   * {@link com.google.devtools.build.android.proto.SerializeFormat.DataValue} entries...
   * </pre>
   *
   * The key and values will be written in comparable order, allowing for the optimization of not
   * converting the DataValue from binary, only writing it into a merged serialized binary.
   */
public void flushTo(Path out) throws IOException {
    Stopwatch timer = Stopwatch.createStarted();
    // Ensure the parent directory exists, if any.
    if (out.getParent() != null) {
        Files.createDirectories(out.getParent());
    }
    try (OutputStream outStream = new BufferedOutputStream(Files.newOutputStream(out, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE))) {
        // Set the header for the deserialization process.
        SerializeFormat.Header.Builder headerBuilder = Header.newBuilder().setEntryCount(entries.size());
        // Create table of source paths to allow references in the serialization format via an index.
        ByteArrayOutputStream sourceTableOutputStream = new ByteArrayOutputStream(2048);
        DataSourceTable sourceTable = DataSourceTable.createAndWrite(entries, sourceTableOutputStream, headerBuilder);
        headerBuilder.build().writeDelimitedTo(outStream);
        writeKeyValuesTo(entries, outStream, sourceTable, sourceTableOutputStream.toByteArray());
    }
    logger.fine(String.format("Serialized merged in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
}
Also used : Header(com.google.devtools.build.android.proto.SerializeFormat.Header) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) Stopwatch(com.google.common.base.Stopwatch) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 65 with BufferedOutputStream

use of java.io.BufferedOutputStream in project camel by apache.

the class ManualGenerator method storeHTMLFile.

private void storeHTMLFile(String content) throws IOException {
    String replaceToken = "<h3 id=\"replaceme\">.*</h3>";
    String replaceValue = "<h3>Version " + version + "</h3>";
    File outFile = new File(output);
    outFile.getParentFile().mkdirs();
    PrintWriter out = new PrintWriter(new BufferedOutputStream(new FileOutputStream(outFile)));
    out.println("<html>");
    out.println("<head>");
    if (head != null) {
        out.println(head);
    }
    out.println("</head>");
    if (replaceToken != null && replaceValue != null) {
        content = content.replaceAll(replaceToken, replaceValue);
    }
    out.print("<body>");
    out.print(content);
    out.println("</body>");
    out.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) PrintWriter(java.io.PrintWriter)

Aggregations

BufferedOutputStream (java.io.BufferedOutputStream)1219 FileOutputStream (java.io.FileOutputStream)861 IOException (java.io.IOException)617 File (java.io.File)519 OutputStream (java.io.OutputStream)350 BufferedInputStream (java.io.BufferedInputStream)238 InputStream (java.io.InputStream)166 DataOutputStream (java.io.DataOutputStream)158 FileInputStream (java.io.FileInputStream)145 ZipOutputStream (java.util.zip.ZipOutputStream)121 FileNotFoundException (java.io.FileNotFoundException)113 ZipEntry (java.util.zip.ZipEntry)108 ByteArrayOutputStream (java.io.ByteArrayOutputStream)101 ZipFile (java.util.zip.ZipFile)62 URL (java.net.URL)57 XmlSerializer (org.xmlpull.v1.XmlSerializer)57 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)56 ObjectOutputStream (java.io.ObjectOutputStream)54 GZIPOutputStream (java.util.zip.GZIPOutputStream)51 PrintStream (java.io.PrintStream)46