Skip to content

Commit 0e3630b

Browse files
committed
Remove unused methods from ZipUtility class
1 parent 49258cd commit 0e3630b

File tree

1 file changed

+1
-81
lines changed
  • roda-common/roda-common-utils/src/main/java/org/roda/core/util

1 file changed

+1
-81
lines changed

roda-common/roda-common-utils/src/main/java/org/roda/core/util/ZipUtility.java

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ public static File createZIPFile(File newZipFile, File contentsDir) throws IOExc
154154
// Create a buffer for reading the files
155155
byte[] buffer = new byte[BUFFER_SIZE];
156156

157-
Iterator<File> iterator = contentAbsoluteFiles.iterator();
158-
while (iterator.hasNext()) {
159-
File absoluteFile = iterator.next();
157+
for (File absoluteFile : contentAbsoluteFiles) {
160158
String relativeFile = getFilePathRelativeTo(absoluteFile, contentsDir);
161159

162160
FileInputStream inputStream = new FileInputStream(absoluteFile);
@@ -196,82 +194,4 @@ public static File createZIPFile(File newZipFile, File contentsDir) throws IOExc
196194
public static String getFilePathRelativeTo(File file, File relativeTo) {
197195
return relativeTo.getAbsoluteFile().toURI().relativize(file.getAbsoluteFile().toURI()).toString();
198196
}
199-
200-
/**
201-
* Adds file / folder to zip output stream. Method works recursively.
202-
*
203-
* @param zos
204-
* @param srcFile
205-
*/
206-
public static void addDirToArchive(ZipOutputStream zos, File srcFile) {
207-
File[] files = srcFile.listFiles();
208-
for (int i = 0; i < files.length; i++) {
209-
// if the file is directory, use recursion
210-
if (files[i].isDirectory()) {
211-
addDirToArchive(zos, files[i]);
212-
continue;
213-
}
214-
try (FileInputStream fis = new FileInputStream(files[i])) {
215-
// create byte buffer
216-
byte[] buffer = new byte[1024];
217-
zos.putNextEntry(new ZipEntry(files[i].getName()));
218-
int length;
219-
while ((length = fis.read(buffer)) > 0) {
220-
zos.write(buffer, 0, length);
221-
}
222-
zos.closeEntry();
223-
} catch (IOException e) {
224-
LOGGER.error("Error adding file/folder to zip", e);
225-
}
226-
}
227-
}
228-
229-
public static void zip(File directory, ZipOutputStream zout) throws IOException {
230-
URI base = directory.toURI();
231-
Deque<File> queue = new LinkedList<>();
232-
queue.push(directory);
233-
try {
234-
while (!queue.isEmpty()) {
235-
File dir = queue.pop();
236-
for (File kid : dir.listFiles()) {
237-
String name = base.relativize(kid.toURI()).getPath();
238-
if (kid.isDirectory()) {
239-
queue.push(kid);
240-
name = name.endsWith("/") ? name : name + "/";
241-
zout.putNextEntry(new ZipEntry(name));
242-
} else {
243-
zout.putNextEntry(new ZipEntry(name));
244-
copy(kid, zout);
245-
zout.closeEntry();
246-
}
247-
}
248-
}
249-
} finally {
250-
zout.close();
251-
}
252-
}
253-
254-
private static void copy(InputStream in, OutputStream out) throws IOException {
255-
byte[] buffer = new byte[1024];
256-
while (true) {
257-
int readCount = in.read(buffer);
258-
if (readCount < 0) {
259-
break;
260-
}
261-
out.write(buffer, 0, readCount);
262-
}
263-
}
264-
265-
private static void copy(File file, OutputStream out) throws IOException {
266-
InputStream in = new FileInputStream(file);
267-
try {
268-
copy(in, out);
269-
} finally {
270-
in.close();
271-
}
272-
}
273-
274-
public static List<File> extractFilesFromInputStream(InputStream inputStream, Path outputDir) throws IOException {
275-
return extractFilesFromInputStream(inputStream, outputDir.toFile(), false);
276-
}
277197
}

0 commit comments

Comments
 (0)