Search in sources :

Example 6 with CustomZipEntry

use of com.facebook.buck.zip.CustomZipEntry in project buck by facebook.

the class CachingBuildEngineTest method writeEntriesToZip.

private static void writeEntriesToZip(Path file, ImmutableMap<Path, String> entries) throws IOException {
    try (CustomZipOutputStream zip = ZipOutputStreams.newOutputStream(file)) {
        for (Map.Entry<Path, String> mapEntry : entries.entrySet()) {
            CustomZipEntry entry = new CustomZipEntry(mapEntry.getKey());
            // We want deterministic ZIPs, so avoid mtimes. -1 is timzeone independent, 0 is not.
            entry.setTime(ZipConstants.getFakeTime());
            // We set the external attributes to this magic value which seems to match the attributes
            // of entries created by {@link InMemoryArtifactCache}.
            entry.setExternalAttributes(33188L << 16);
            zip.putNextEntry(entry);
            zip.write(mapEntry.getValue().getBytes());
            zip.closeEntry();
        }
    }
}
Also used : Path(java.nio.file.Path) LazyPath(com.facebook.buck.io.LazyPath) BorrowablePath(com.facebook.buck.io.BorrowablePath) CustomZipOutputStream(com.facebook.buck.zip.CustomZipOutputStream) CustomZipEntry(com.facebook.buck.zip.CustomZipEntry) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Aggregations

CustomZipEntry (com.facebook.buck.zip.CustomZipEntry)6 CustomZipOutputStream (com.facebook.buck.zip.CustomZipOutputStream)3 Path (java.nio.file.Path)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 InputStream (java.io.InputStream)2 Map (java.util.Map)2 BorrowablePath (com.facebook.buck.io.BorrowablePath)1 LazyPath (com.facebook.buck.io.LazyPath)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 HashMap (java.util.HashMap)1