gpt4 book ai didi

org.batfish.common.util.ZipUtility类的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 07:11:31 27 4
gpt4 key购买 nike

本文整理了Java中org.batfish.common.util.ZipUtility类的一些代码示例,展示了ZipUtility类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipUtility类的具体详情如下:
包路径:org.batfish.common.util.ZipUtility
类名称:ZipUtility

ZipUtility介绍

暂无

代码示例

代码示例来源:origin: batfish/batfish

private static void addFolderToZip(String path, String srcFolder, ZipOutputStream zip)
  throws Exception {
 File folder = new File(srcFolder);
 /*
  * check the empty folder
  */
 // ratul comments the lines below
 // if (folder.list().length == 0) {
 // System.out.println(folder.getName());
 addFileToZip(path, srcFolder, zip, true);
 // } else {
 /*
  * list the files in the folder
  */
 for (String fileName : folder.list()) {
  if (path.equals("")) {
   addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip, false);
  } else {
   addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip, false);
  }
 }
 // }
}

代码示例来源:origin: batfish/batfish

private static void zipFolder(String srcFolder, OutputStream outputStream, Closer closer)
   throws Exception {
  ZipOutputStream zip = null;
  /*
   * create the output stream to zip file result
   */
  zip = closer.register(new ZipOutputStream(outputStream));
  /*
   * add the folder to the zip
   */
  addFolderToZip("", srcFolder, zip);
 }
}

代码示例来源:origin: batfish/batfish

@MustBeClosed
@Override
public @Nonnull InputStream loadSnapshotInputObject(
  NetworkId networkId, SnapshotId snapshotId, String key)
  throws FileNotFoundException, IOException {
 Path objectPath = getSnapshotInputObjectPath(networkId, snapshotId, key);
 if (!Files.exists(objectPath)) {
  throw new FileNotFoundException(String.format("Could not load: %s", objectPath));
 }
 return Files.isDirectory(objectPath)
   ? ZipUtility.zipFilesToInputStream(objectPath)
   : Files.newInputStream(objectPath);
}

代码示例来源:origin: batfish/batfish

private boolean uploadTestrig(String fileOrDir, String testrigName, boolean autoAnalyze) {
 Path initialUploadTarget = Paths.get(fileOrDir);
 Path uploadTarget = initialUploadTarget;
 boolean createZip = Files.isDirectory(initialUploadTarget);
 if (createZip) {
  uploadTarget = CommonUtil.createTempFile("testrig", "zip");
  ZipUtility.zipFiles(initialUploadTarget.toAbsolutePath(), uploadTarget.toAbsolutePath());
 }
 try {
  boolean result =
    _workHelper.uploadSnapshot(
      _currContainerName, testrigName, uploadTarget.toString(), autoAnalyze);
  return result;
 } finally {
  if (createZip) {
   CommonUtil.delete(uploadTarget);
  }
 }
}

代码示例来源:origin: batfish/batfish

/** Zip {@code srcFolder} and write to {@code destZipFile} */
public static void zipFiles(Path srcFolder, Path destZipFile) {
 try (Closer closer = Closer.create()) {
  OutputStream fos = closer.register(Files.newOutputStream(destZipFile));
  zipFolder(srcFolder.toString(), fos, closer);
 } catch (Exception e) {
  throw new BatfishException(
    "Could not zip folder: '" + srcFolder + "' into: '" + destZipFile + "'", e);
 }
}

代码示例来源:origin: batfish/batfish

@Nullable
@Deprecated
public Path getTestrigObject(String networkName, String testrigName, String objectName) {
 Path testrigDir = getdirSnapshot(networkName, testrigName);
 Path file = testrigDir.resolve(Paths.get(BfConsts.RELPATH_OUTPUT, objectName));
 /*
  * Check if we got an object name outside of the testrig folder, perhaps because of ".." in the
  * name; disallow it
  */
 if (!CommonUtil.getCanonicalPath(file).startsWith(CommonUtil.getCanonicalPath(testrigDir))) {
  throw new BatfishException("Illegal object name: '" + objectName + "'");
 }
 // Check in output then input directories for backward compatibility
 // Since inputs and outputs used to be stored together, in the testrig dir
 if (!file.toFile().exists()) {
  file = testrigDir.resolve(Paths.get(BfConsts.RELPATH_INPUT, objectName));
 }
 if (Files.isRegularFile(file)) {
  return file;
 } else if (Files.isDirectory(file)) {
  Path zipfile = Paths.get(file + ".zip");
  if (Files.exists(zipfile)) {
   CommonUtil.deleteIfExists(zipfile);
  }
  ZipUtility.zipFiles(file, zipfile);
  // TODO: delete the zipfile
  return zipfile;
 }
 return null;
}

代码示例来源:origin: batfish/batfish

/** Zip {@code srcFolder} in memory and return input stream from which zip may be read. */
@MustBeClosed
public static @Nonnull InputStream zipFilesToInputStream(Path srcFolder) {
 ByteArrayOutputStream baos;
 try (Closer closer = Closer.create()) {
  baos = closer.register(new ByteArrayOutputStream());
  zipFolder(srcFolder.toString(), baos, closer);
 } catch (Exception e) {
  throw new BatfishException("Could not zip folder: '" + srcFolder + "'", e);
 }
 return new ByteArrayInputStream(baos.toByteArray());
}

代码示例来源:origin: batfish/batfish

/** Creates a snapshot zip with the specified config and returns the path to that zip */
 public static Path createSnapshotZip(
   String snapshot, String fileName, String content, TemporaryFolder folder) {
  Path tmpSnapshotSrcDir = createSnapshot(snapshot, fileName, content, folder);

  Path tmpSnapshotZip = tmpSnapshotSrcDir.resolve(String.format("%s.zip", snapshot));
  ZipUtility.zipFiles(tmpSnapshotSrcDir.resolve(snapshot), tmpSnapshotZip);
  return tmpSnapshotZip;
 }
}

代码示例来源:origin: batfish/batfish

addFolderToZip(path, srcFile, zip);
} else {

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com