Java 类com.intellij.util.io.zip.JBZipEntry 实例源码

项目:educational-plugin    文件:StudyProjectGenerator.java   
@Nullable
public static Course getCourse(String zipFilePath) {
  try {
    final JBZipFile zipFile = new JBZipFile(zipFilePath);
    final JBZipEntry entry = zipFile.getEntry(EduNames.COURSE_META_FILE);
    if (entry == null) {
      return null;
    }
    byte[] bytes = entry.getData();
    final String jsonText = new String(bytes, CharsetToolkit.UTF8_CHARSET);
    Gson gson = new GsonBuilder()
      .registerTypeAdapter(Task.class, new StudySerializationUtils.Json.TaskAdapter())
      .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
      .create();
    return gson.fromJson(jsonText, Course.class);
  }
  catch (IOException e) {
    LOG.error("Failed to unzip course archive");
    LOG.error(e);
  }
  return null;
}
项目:intellij-ce-playground    文件:ReorderJarsTest.java   
@Test
public void testPluginXml() throws Exception {
  String path = getTestDataPath() + "/ide/plugins/reorderJars";

  ReorderJarsMain.main(new String[] { path + "/zkmOrder.txt", path, myTempDirectory.getPath() } );

  File[] files = myTempDirectory.listFiles();
  assertNotNull(files);
  File file = files[0];
  assertEquals("zkm.jar", file.getName());

  JBZipFile zipFile = new JBZipFile(file);
  try {
    List<JBZipEntry> entries = zipFile.getEntries();
    System.out.println(entries);
    assertEquals(JarMemoryLoader.SIZE_ENTRY, entries.get(0).getName());
    assertEquals("META-INF/plugin.xml", entries.get(1).getName());
  }
  finally {
    zipFile.close();
  }
}
项目:intellij-ce-playground    文件:WorkingContextManager.java   
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(comment);
    }
    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);
  }
}
项目:intellij-ce-playground    文件:WorkingContextManager.java   
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();
      Document document = JDOMUtil.loadDocument(new String(bytes));
      Element rootElement = document.getRootElement();
      loadContext(rootElement);
      return true;
    }
  }
  catch (Exception e) {
    LOG.error(e);
  }
  finally {
    closeArchive(archive);
  }
  return false;
}
项目:intellij-ce-playground    文件:WorkingContextManager.java   
private synchronized List<ContextInfo> getContextHistory(String zipPostfix) {
  JBZipFile archive = null;
  try {
    archive = getTasksArchive(zipPostfix);
    List<JBZipEntry> entries = archive.getEntries();
    return ContainerUtil.mapNotNull(entries, new NullableFunction<JBZipEntry, ContextInfo>() {
      public ContextInfo fun(JBZipEntry entry) {
        return entry.getName().startsWith("/context") ? new ContextInfo(entry.getName(), entry.getTime(), entry.getComment()) : null;
      }
    });
  }
  catch (IOException e) {
    LOG.error(e);
    return Collections.emptyList();
  }
  finally {
    closeArchive(archive);
  }
}
项目:intellij-ce-playground    文件:WorkingContextManager.java   
private void removeContext(String name, String postfix) {
  JBZipFile archive = null;
  try {
    archive = getTasksArchive(postfix);
    JBZipEntry entry = archive.getEntry(name);
    if (entry != null) {
      archive.eraseEntry(entry);
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
  finally {
    closeArchive(archive);
  }
}
项目:intellij-ce-playground    文件:WorkingContextManager.java   
private synchronized void pack(int max, int delta, String zipPostfix) {
  JBZipFile archive = null;
  try {
    archive = getTasksArchive(zipPostfix);
    List<JBZipEntry> entries = archive.getEntries();
    if (entries.size() > max + delta) {
      JBZipEntry[] array = entries.toArray(new JBZipEntry[entries.size()]);
      Arrays.sort(array, ENTRY_COMPARATOR);
      for (int i = array.length - 1; i >= max; i--) {
        archive.eraseEntry(array[i]);
      }
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
  finally {
    closeArchive(archive);
  }
}
项目:tools-idea    文件:WorkingContextManager.java   
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(comment);
    }
    Element element = new Element("context");
    saveContext(element);
    String s = new XMLOutputter().outputString(element);
    entry.setData(s.getBytes("UTF-8"));
  }
  catch (IOException e) {
    LOG.error(e);
  }
  finally {
    closeArchive(archive);
  }
}
项目:tools-idea    文件:WorkingContextManager.java   
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();
      Document document = JDOMUtil.loadDocument(new String(bytes));
      Element rootElement = document.getRootElement();
      loadContext(rootElement);
      return true;
    }
  }
  catch (Exception e) {
    LOG.error(e);
  }
  finally {
    closeArchive(archive);
  }
  return false;
}
项目:tools-idea    文件:WorkingContextManager.java   
private synchronized List<ContextInfo> getContextHistory(String zipPostfix) {
  JBZipFile archive = null;
  try {
    archive = getTasksArchive(zipPostfix);
    List<JBZipEntry> entries = archive.getEntries();
    return ContainerUtil.mapNotNull(entries, new NullableFunction<JBZipEntry, ContextInfo>() {
      public ContextInfo fun(JBZipEntry entry) {
        return entry.getName().startsWith("/context") ? new ContextInfo(entry.getName(), entry.getTime(), entry.getComment()) : null;
      }
    });
  }
  catch (IOException e) {
    LOG.error(e);
    return Collections.emptyList();
  }
  finally {
    closeArchive(archive);
  }
}
项目:tools-idea    文件:WorkingContextManager.java   
private void removeContext(String name, String postfix) {
  JBZipFile archive = null;
  try {
    archive = getTasksArchive(postfix);
    JBZipEntry entry = archive.getEntry(name);
    if (entry != null) {
      archive.eraseEntry(entry);
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
  finally {
    closeArchive(archive);
  }
}
项目:tools-idea    文件:WorkingContextManager.java   
private synchronized void pack(int max, int delta, String zipPostfix) {
  JBZipFile archive = null;
  try {
    archive = getTasksArchive(zipPostfix);
    List<JBZipEntry> entries = archive.getEntries();
    if (entries.size() > max + delta) {
      JBZipEntry[] array = entries.toArray(new JBZipEntry[entries.size()]);
      Arrays.sort(array, ENTRY_COMPARATOR);
      for (int i = array.length - 1; i >= max; i--) {
        archive.eraseEntry(array[i]);
      }
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
  finally {
    closeArchive(archive);
  }
}
项目:consulo-tasks    文件:WorkingContextManager.java   
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(comment);
    }
    Element element = new Element("context");
    saveContext(element);
    String s = new XMLOutputter().outputString(element);
    entry.setData(s.getBytes("UTF-8"));
  }
  catch (IOException e) {
    LOG.error(e);
  }
  finally {
    closeArchive(archive);
  }
}
项目:consulo-tasks    文件:WorkingContextManager.java   
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();
      Document document = JDOMUtil.loadDocument(new String(bytes));
      Element rootElement = document.getRootElement();
      loadContext(rootElement);
      return true;
    }
  }
  catch (Exception e) {
    LOG.error(e);
  }
  finally {
    closeArchive(archive);
  }
  return false;
}
项目:consulo-tasks    文件:WorkingContextManager.java   
private synchronized List<ContextInfo> getContextHistory(String zipPostfix) {
  JBZipFile archive = null;
  try {
    archive = getTasksArchive(zipPostfix);
    List<JBZipEntry> entries = archive.getEntries();
    return ContainerUtil.mapNotNull(entries, new NullableFunction<JBZipEntry, ContextInfo>() {
      public ContextInfo fun(JBZipEntry entry) {
        return entry.getName().startsWith("/context") ? new ContextInfo(entry.getName(), entry.getTime(), entry.getComment()) : null;
      }
    });
  }
  catch (IOException e) {
    LOG.error(e);
    return Collections.emptyList();
  }
  finally {
    closeArchive(archive);
  }
}
项目:consulo-tasks    文件:WorkingContextManager.java   
private void removeContext(String name, String postfix) {
  JBZipFile archive = null;
  try {
    archive = getTasksArchive(postfix);
    JBZipEntry entry = archive.getEntry(name);
    if (entry != null) {
      archive.eraseEntry(entry);
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
  finally {
    closeArchive(archive);
  }
}
项目:consulo-tasks    文件:WorkingContextManager.java   
private synchronized void pack(int max, int delta, String zipPostfix) {
  JBZipFile archive = null;
  try {
    archive = getTasksArchive(zipPostfix);
    List<JBZipEntry> entries = archive.getEntries();
    if (entries.size() > max + delta) {
      JBZipEntry[] array = entries.toArray(new JBZipEntry[entries.size()]);
      Arrays.sort(array, ENTRY_COMPARATOR);
      for (int i = array.length - 1; i >= max; i--) {
        archive.eraseEntry(array[i]);
      }
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
  finally {
    closeArchive(archive);
  }
}
项目:intellij-ce-playground    文件:WorkingContextManager.java   
public int compare(JBZipEntry o1, JBZipEntry o2) {
  return Long.signum(o2.getTime() - o1.getTime());
}
项目:tools-idea    文件:WorkingContextManager.java   
public int compare(JBZipEntry o1, JBZipEntry o2) {
  return Long.signum(o2.getTime() - o1.getTime());
}
项目:consulo-tasks    文件:WorkingContextManager.java   
public int compare(JBZipEntry o1, JBZipEntry o2) {
  return Long.signum(o2.getTime() - o1.getTime());
}