MCPcopy Create free account
hub / github.com/ReadyTalk/avian / createZip

Method createZip

test/ZipOutputStreamTest.java:60–132  ·  view source on GitHub ↗
(boolean useOneParam)

Source from the content-addressed store, hash-verified

58 }
59
60 private static File createZip(boolean useOneParam)
61 {
62 FileOutputStream outputStream = null;
63 ZipOutputStream zipContents = null;
64
65 try
66 {
67 // Create a temporary zip file for this test
68 String prefix = useOneParam ? ONE_PARAM_ZIP_PREFIX : THREE_PARAM_ZIP_PREFIX;
69 File outputZip = File.createTempFile(prefix, ZIP_SUFFIX);
70
71 System.out.println("Created " + outputZip.getAbsolutePath());
72
73 // Prepare the streams
74 outputStream = new FileOutputStream(outputZip);
75 zipContents = new ZipOutputStream(outputStream);
76
77 // Zip the file contents (convert directly from string to bytes)
78 long startTime = System.currentTimeMillis();
79 for (Map.Entry<String, String> f : FILES_CONTENTS.entrySet())
80 {
81 String name = f.getKey();
82 String contents = f.getValue();
83
84 System.out.println("Zipping " + name + "...");
85 ZipEntry entry = new ZipEntry(name);
86 zipContents.putNextEntry(entry);
87
88 byte[] bytesToWrite = contents.getBytes();
89
90 if (useOneParam)
91 {
92 // Use the 1-parameter write method; takes a single byte
93 for (int i = 0; i < bytesToWrite.length; i++)
94 {
95 zipContents.write(bytesToWrite[i]);
96 }
97 }
98 else
99 {
100 // Use 3-parameter write method; takes a buffer, offset, and length
101 zipContents.write(bytesToWrite, 0 , bytesToWrite.length);
102 }
103
104 // Done with this file
105 zipContents.closeEntry();
106 System.out.println("Done");
107 }
108
109 // All files have been written
110 long endTime = System.currentTimeMillis();
111 System.out.println("Finished " + outputZip.getName() + " in " + ((endTime - startTime) / 1000.0) + " seconds");
112 return outputZip;
113 }
114 catch (Exception e)
115 {
116 throw new RuntimeException(e);
117 }

Callers 1

mainMethod · 0.95

Calls 14

createTempFileMethod · 0.95
getAbsolutePathMethod · 0.95
currentTimeMillisMethod · 0.95
putNextEntryMethod · 0.95
getBytesMethod · 0.95
writeMethod · 0.95
closeEntryMethod · 0.95
getNameMethod · 0.95
closeMethod · 0.95
closeMethod · 0.95
entrySetMethod · 0.65
getKeyMethod · 0.65

Tested by

no test coverage detected