コード例 #1
0
 public void putArtifact(ArtifactContext context, InputStream content) throws RepositoryException {
   try {
     final Node parent = getOrCreateParent(context);
     log.debug("Adding artifact " + context + " to cache " + cache.getDisplayString());
     log.debug(" -> " + NodeUtils.getFullPath(parent));
     final String[] names = cache.getArtifactNames(context);
     if (names.length != 1) {
       throw new RepositoryException("ArtifactContext should have a single suffix");
     }
     final String label = names[0];
     try {
       if (parent instanceof OpenNode) {
         final OpenNode on = (OpenNode) parent;
         if (on.addContent(label, content, context) == null)
           addContent(context, parent, label, content);
       } else {
         addContent(context, parent, label, content);
       }
     } catch (IOException e) {
       throw new RepositoryException(e);
     }
     log.debug(" -> [done]");
   } finally {
     IOUtils.safeClose(content);
   }
 }
コード例 #2
0
  protected void putFiles(OpenNode current, File file, ArtifactContext context) throws IOException {
    if (current == null)
      throw new IOException(
          "Null current, could probably not create new node for file: " + file.getParent());

    if (file.isDirectory()) {
      current = current.createNode(file.getName());
      for (File f : file.listFiles()) putFiles(current, f, context);
    } else {
      log.debug(" Adding file " + file.getPath() + " at " + NodeUtils.getFullPath(current));
      // Not the same file so we can add it
      try (InputStream in = new FileInputStream(file)) {
        current.addContent(file.getName(), in, context);
      }
      log.debug("  -> [done]");
    }
  }