Package java.security

Examples of java.security.DigestOutputStream


    private void renderPDF(String fo, String digestIn, String digestOut)
        throws Exception {
        FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
        foUserAgent.setCreationDate(new Date(10000));
        MessageDigest outDigest = MessageDigest.getInstance("MD5");
        DigestOutputStream out =
            new DigestOutputStream(new ByteArrayOutputStream(), outDigest);
        Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
        InputSource source = new InputSource(new StringReader(fo));
        DigestFilter filter = new DigestFilter("MD5");
        filter.setParent(parserFactory.newSAXParser().getXMLReader());
        filter.setContentHandler(fop.getDefaultHandler());
View Full Code Here


            DataIdentifier tempId = new DataIdentifier(temporary.getName());
            usesIdentifier(tempId);
            // Copy the stream to the temporary file and calculate the
            // stream length and the message digest of the stream
            MessageDigest digest = MessageDigest.getInstance(DIGEST);
            OutputStream output = new DigestOutputStream(new FileOutputStream(
                temporary), digest);
            try {
                IOUtils.copyLarge(input, output);
            } finally {
                output.close();
            }
            DataIdentifier identifier = new DataIdentifier(
                encodeHexString(digest.digest()));
            synchronized (this) {
                usesIdentifier(identifier);
View Full Code Here

            final OutputStream os = new OutputStream() {
                public void write(int b) throws IOException {
                    //
                }
            };
            final DigestOutputStream dos = new DigestOutputStream(os, messageDigest);
            calculateHash(file, dos);
            sha1Bytes = messageDigest.digest();
        }
        final File content = getExternalFileReference(sha1Bytes, true);
        final OutputStream os = new FileOutputStream(content);
View Full Code Here

           throws Exception
   {
      long hash = 0;
      ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(512);
      MessageDigest messagedigest = MessageDigest.getInstance("SHA");
      DataOutputStream dataoutputstream = new DataOutputStream(new DigestOutputStream(bytearrayoutputstream, messagedigest));
      dataoutputstream.writeUTF(methodDesc);
      dataoutputstream.flush();
      byte abyte0[] = messagedigest.digest();
      for (int j = 0; j < Math.min(8, abyte0.length); j++)
         hash += (long) (abyte0[j] & 0xff) << j * 8;
 
View Full Code Here

    }
  }

  void writeTo(final OutputStream os) throws IOException {
    final MessageDigest foot = Constants.newMessageDigest();
    final DigestOutputStream dos = new DigestOutputStream(os, foot);

    boolean extended = false;
    for (int i = 0; i < entryCnt; i++)
      extended |= sortedEntries[i].isExtended();

    // Write the header.
    //
    final byte[] tmp = new byte[128];
    System.arraycopy(SIG_DIRC, 0, tmp, 0, SIG_DIRC.length);
    NB.encodeInt32(tmp, 4, extended ? 3 : 2);
    NB.encodeInt32(tmp, 8, entryCnt);
    dos.write(tmp, 0, 12);

    // Write the individual file entries.
    //
    if (lastModified <= 0) {
      // Write a new index, as no entries require smudging.
      //
      for (int i = 0; i < entryCnt; i++)
        sortedEntries[i].write(dos);
    } else {
      final int smudge_s = (int) (lastModified / 1000);
      final int smudge_ns = ((int) (lastModified % 1000)) * 1000000;
      for (int i = 0; i < entryCnt; i++) {
        final DirCacheEntry e = sortedEntries[i];
        if (e.mightBeRacilyClean(smudge_s, smudge_ns))
          e.smudgeRacilyClean();
        e.write(dos);
      }
    }

    if (tree != null) {
      final TemporaryBuffer bb = new TemporaryBuffer.LocalFile();
      tree.write(tmp, bb);
      bb.close();

      NB.encodeInt32(tmp, 0, EXT_TREE);
      NB.encodeInt32(tmp, 4, (int) bb.length());
      dos.write(tmp, 0, 8);
      bb.writeTo(dos, null);
    }

    os.write(foot.digest());
    os.close();
View Full Code Here

        byte[] block = new byte[blockSize];
        int count = 0;
        while (true) {
            MessageDigest messageDigest = MessageDigest.getInstance(HASH_ALGORITHM);
            ByteArrayOutputStream buff = new ByteArrayOutputStream();
            DigestOutputStream dout = new DigestOutputStream(buff, messageDigest);
            int blockLen = IOUtils.readFully(in, block, 0, block.length);
            count++;
            if (blockLen == 0) {
                break;
            } else if (blockLen < blockSizeMin) {
                idStream.write(TYPE_DATA);
                IOUtils.writeVarInt(idStream, blockLen);
                idStream.write(block, 0, blockLen);
                totalLength += blockLen;
            } else {
                dout.write(block, 0, blockLen);
                byte[] digest = messageDigest.digest();
                idStream.write(TYPE_HASH);
                IOUtils.writeVarInt(idStream, level);
                if (level > 0) {
                    IOUtils.writeVarLong(idStream, totalLength);
View Full Code Here

            usesIdentifier(tempId);
            // Copy the stream to the temporary file and calculate the
            // stream length and the message digest of the stream
            long length = 0;
            MessageDigest digest = MessageDigest.getInstance(DIGEST);
            OutputStream output = new DigestOutputStream(
                    new FileOutputStream(temporary), digest);
            try {
                length = IOUtils.copyLarge(input, output);
            } finally {
                output.close();
            }
            DataIdentifier identifier = new DataIdentifier(digest.digest());
            File file;

            synchronized (this) {
View Full Code Here

        } finally {
          destroy();
        }
      }
    };
    return encryption.encrypt(new DigestOutputStream(buffer, md5));
  }
View Full Code Here

      try {
        OutputStream out = fOut;
        if (config.getFSyncObjectFiles())
          out = Channels.newOutputStream(fOut.getChannel());
        DeflaterOutputStream cOut = compress(out);
        DigestOutputStream dOut = new DigestOutputStream(cOut, md);
        writeHeader(dOut, type, len);

        final byte[] buf = buffer();
        while (len > 0) {
          int n = is.read(buf, 0, (int) Math.min(len, buf.length));
          if (n <= 0)
            throw shortInput(len);
          dOut.write(buf, 0, n);
          len -= n;
        }
        dOut.flush();
        cOut.finish();
      } finally {
        if (config.getFSyncObjectFiles())
          fOut.getChannel().force(true);
        fOut.close();
View Full Code Here

   * @param dst
   *            the stream this instance outputs to. If not already buffered
   *            it will be automatically wrapped in a buffered stream.
   */
  protected PackIndexWriter(final OutputStream dst) {
    out = new DigestOutputStream(dst instanceof BufferedOutputStream ? dst
        : new BufferedOutputStream(dst), Constants.newMessageDigest());
    tmp = new byte[4 + Constants.OBJECT_ID_LENGTH];
  }
View Full Code Here

TOP

Related Classes of java.security.DigestOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.