Beispiel #1
0
      @Override
      public byte[] addContent(InputStream stream) throws IOException {
        byte[] sha1Bytes;
        File tmp = File.createTempFile(CONTENT, "tmp", repoRoot);
        FileOutputStream fos = new FileOutputStream(tmp);
        synchronized (messageDigest) {
          messageDigest.reset();
          try {
            DigestOutputStream dos = new DigestOutputStream(fos, messageDigest);
            BufferedInputStream bis = new BufferedInputStream(stream);
            byte[] bytes = new byte[8192];
            int read;
            while ((read = bis.read(bytes)) > -1) {
              dos.write(bytes, 0, read);
            }
          } finally {
            safeClose(fos);
          }
          sha1Bytes = messageDigest.digest();
        }
        final File realFile = getDeploymentContentFile(sha1Bytes, true);
        if (hasContent(sha1Bytes)) {
          // we've already got this content
          if (!tmp.delete()) {
            tmp.deleteOnExit();
          }
          DeploymentRepositoryLogger.ROOT_LOGGER.debugf(
              "Content was already present in repository at location %s",
              realFile.getAbsolutePath());
        } else {
          moveTempToPermanent(tmp, realFile);
          DeploymentRepositoryLogger.ROOT_LOGGER.contentAdded(realFile.getAbsolutePath());
        }

        return sha1Bytes;
      }
Beispiel #2
0
 @Override
 public void removeContent(byte[] hash) {
   File file = getDeploymentContentFile(hash, true);
   if (!file.delete()) {
     file.deleteOnExit();
   }
   File parent = file.getParentFile();
   if (!parent.delete()) {
     parent.deleteOnExit();
   }
   parent = parent.getParentFile();
   if (parent.list().length == 0) {
     if (!parent.delete()) {
       parent.deleteOnExit();
     }
   }
   DeploymentRepositoryLogger.ROOT_LOGGER.contentRemoved(file.getAbsolutePath());
 }
Beispiel #3
0
 @Override
 public void stop(StopContext context) {
   DeploymentRepositoryLogger.ROOT_LOGGER.debugf(
       "%s stopped", ContentRepository.class.getSimpleName());
 }
Beispiel #4
0
 @Override
 public void start(StartContext context) throws StartException {
   DeploymentRepositoryLogger.ROOT_LOGGER.debugf(
       "%s started", ContentRepository.class.getSimpleName());
 }