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;
      }