use of com.intellij.util.io.zip.JBZipFile in project intellij-community by JetBrains.
the class ReorderJarsTest method testReordering.
@Test
public void testReordering() throws IOException {
String path = getTestDataPath() + "/ide/plugins/reorderJars";
JBZipFile zipFile1 = new JBZipFile(path + "/annotations.jar");
try {
List<JBZipEntry> entries = zipFile1.getEntries();
System.out.println(entries);
} finally {
zipFile1.close();
}
ReorderJarsMain.main(new String[] { path + "/order.txt", path, myTempDirectory.getPath() });
File[] files = myTempDirectory.listFiles();
assertNotNull(files);
assertEquals(1, files.length);
File file = files[0];
assertEquals("annotations.jar", file.getName());
byte[] data;
JBZipFile zipFile2 = new JBZipFile(file);
try {
List<JBZipEntry> entries = zipFile2.getEntries();
System.out.println(entries);
assertEquals(JarMemoryLoader.SIZE_ENTRY, entries.get(0).getName());
JBZipEntry entry = entries.get(1);
data = entry.getData();
assertEquals(548, data.length);
assertEquals("org/jetbrains/annotations/Nullable.class", entry.getName());
assertEquals("org/jetbrains/annotations/NotNull.class", entries.get(2).getName());
assertEquals("META-INF/", entries.get(3).getName());
} finally {
zipFile2.close();
}
ZipFile zipFile3 = new ZipFile(file);
try {
JarMemoryLoader loader = JarMemoryLoader.load(zipFile3, file.toURI().toURL(), null);
assertNotNull(loader);
Resource resource = loader.getResource("org/jetbrains/annotations/Nullable.class");
assertNotNull(resource);
byte[] bytes = resource.getBytes();
assertEquals(548, bytes.length);
assertTrue(Arrays.equals(data, bytes));
} finally {
zipFile3.close();
}
}
use of com.intellij.util.io.zip.JBZipFile in project intellij-community by JetBrains.
the class WorkingContextManager method saveContext.
private synchronized void saveContext(@Nullable String entryName, String zipPostfix, @Nullable String comment) {
JBZipFile archive = null;
try {
archive = getTasksArchive(zipPostfix);
if (entryName == null) {
int i = archive.getEntries().size();
do {
entryName = "context" + i++;
} while (archive.getEntry("/" + entryName) != null);
}
JBZipEntry entry = archive.getOrCreateEntry("/" + entryName);
if (comment != null) {
entry.setComment(StringUtil.first(comment, 200, true));
}
Element element = new Element("context");
saveContext(element);
String s = new XMLOutputter().outputString(element);
entry.setData(s.getBytes(CharsetToolkit.UTF8_CHARSET));
} catch (IOException e) {
LOG.error(e);
} finally {
closeArchive(archive);
}
}
use of com.intellij.util.io.zip.JBZipFile in project intellij-community by JetBrains.
the class WorkingContextManager method loadContext.
private synchronized boolean loadContext(String zipPostfix, String entryName) {
JBZipFile archive = null;
try {
archive = getTasksArchive(zipPostfix);
JBZipEntry entry = archive.getEntry(StringUtil.startsWithChar(entryName, '/') ? entryName : "/" + entryName);
if (entry != null) {
byte[] bytes = entry.getData();
loadContext(JdomKt.loadElement(new String(bytes)));
return true;
}
} catch (Exception e) {
LOG.error(e);
} finally {
closeArchive(archive);
}
return false;
}
Aggregations