use of java.util.zip.ZipOutputStream 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.util.zip.ZipOutputStream 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.util.zip.ZipOutputStream in project buck by facebook.
the class CustomZipEntryTest method writeSimpleJarAndGetHash.
private HashCode writeSimpleJarAndGetHash() throws Exception {
Path output = Files.createTempFile("example", ".jar");
try (FileOutputStream fileOutputStream = new FileOutputStream(output.toFile());
ZipOutputStream out = new JarOutputStream(fileOutputStream)) {
ZipEntry entry = new CustomZipEntry("test");
out.putNextEntry(entry);
out.write(new byte[0]);
entry = new ZipEntry("test1");
entry.setTime(ZipConstants.getFakeTime());
out.putNextEntry(entry);
out.write(new byte[0]);
}
return Hashing.sha1().hashBytes(Files.readAllBytes(output));
}
use of java.util.zip.ZipOutputStream in project buck by facebook.
the class RepackZipEntriesStepTest method buildSampleZipFile.
@Before
public void buildSampleZipFile() throws IOException {
parent = tmp.newFolder("foo");
filesystem = new ProjectFilesystem(parent);
zipFile = parent.resolve("example.zip");
// Since we've modeled our outputstreams after the zip output stream, be compatible with that.
try (ZipOutputStream stream = new ZipOutputStream(Files.newOutputStream(zipFile))) {
ZipEntry entry = new ZipEntry("file");
stream.putNextEntry(entry);
String packageName = getClass().getPackage().getName().replace(".", "/");
URL sample = Resources.getResource(packageName + "/sample-bytes.properties");
stream.write(Resources.toByteArray(sample));
}
}
use of java.util.zip.ZipOutputStream in project translationstudio8 by heartsome.
the class ZipUtil method zipFolder.
/**
* 压缩文件夹
* @param zipPath
* 生成的zip文件路径
* @param filePath
* 需要压缩的文件夹路径
* @throws Exception
*/
public static void zipFolder(String zipPath, String filePath) throws IOException {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipPath));
File f = new File(filePath);
zipFiles(out, f, "");
out.close();
}
Aggregations