added tests for detect files inside .jar

This commit is contained in:
Alexey Kudravtsev
2017-02-14 14:02:47 +03:00
parent 306089db26
commit 7bb4088e18
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.util.io;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.CharsetToolkit;
@@ -26,6 +27,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.*;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.util.Collection;
import java.util.Locale;
import java.util.Set;
import java.util.jar.JarFile;
@@ -201,11 +203,28 @@ public class IoTestUtil {
}
@NotNull
public static File createTestJar(@NotNull File jarFile, @NotNull String... data) {
public static File createTestJar(@NotNull File jarFile, @NotNull String... namesAndTexts) {
try (ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(jarFile))) {
for (int i = 0; i < data.length; i += 2) {
stream.putNextEntry(new ZipEntry(data[i]));
stream.write(data[i + 1].getBytes(CharsetToolkit.UTF8_CHARSET));
for (int i = 0; i < namesAndTexts.length; i += 2) {
stream.putNextEntry(new ZipEntry(namesAndTexts[i]));
stream.write(namesAndTexts[i + 1].getBytes(CharsetToolkit.UTF8_CHARSET));
stream.closeEntry();
}
return jarFile;
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@NotNull
public static File createTestJar(@NotNull File jarFile, @NotNull Collection<Pair<String,byte[]>> namesAndContents) {
try (ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(jarFile))) {
for (Pair<String, byte[]> p : namesAndContents) {
String name = p.first;
byte[] content = p.second;
stream.putNextEntry(new ZipEntry(name));
stream.write(content);
stream.closeEntry();
}
return jarFile;