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();
}
}
}
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);
}
}
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);
}
}
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)));
}
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();
}
Aggregations