Package com.caucho.vfs

Examples of com.caucho.vfs.TempOutputStream


                                  CacheSerializer serializer)
  {
    if (valueKey == null || valueKey == HashManager.NULL)
      return null;

    TempOutputStream os = null;

    try {
      os = new TempOutputStream();

      WriteStream out = Vfs.openWrite(os);

      if (! getDataBacking().loadData(valueKey, out)) {
        if (! loadClusterData(valueKey, flags)) {
          log.warning(this + " cannot load data for " + valueKey + " from triad");
         
          out.close();
       
          return null;
        }

        if (! getDataBacking().loadData(valueKey, out)) {
          out.close();
       
          return null;
        }
      }

      out.close();

      InputStream is = os.openInputStream();

      try {
        InflaterInputStream gzIn = new InflaterInputStream(is);

        Object value = serializer.deserialize(gzIn);

        gzIn.close();

        return value;
      } finally {
        is.close();
      }
    } catch (Exception e) {
      log.log(Level.WARNING, e.toString(), e);
     
      return null;
    } finally {
      if (os != null)
        os.close();
    }
  }
View Full Code Here


        }
       
        return true;
      }

      TempOutputStream os = new TempOutputStream();

      if (cache.get(_id, os)) {
        InputStream is = os.getInputStream();

        SessionDeserializer in = _manager.createSessionDeserializer(is);

        if (log.isLoggable(Level.FINE)) {
          log.fine(this + " session load valueHash="
View Full Code Here

      if (! _manager.isPersistenceEnabled())
        return;

      _isModified = false;

      TempOutputStream os = new TempOutputStream();
      SessionSerializer out = _manager.createSessionSerializer(os);

      store(out);

      out.close();

      _manager.addSessionSaveSample(os.getLength());

      _cacheEntry = _manager.getCache().put(_id, os.getInputStream(),
                                            _idleTimeout);

      if (log.isLoggable(Level.FINE)) {
        log.fine(this + " session save valueHash="
                 + (_cacheEntry != null ? _cacheEntry.getValueHashKey() : null));
      }

      os.close();
    } catch (Exception e) {
      log.log(Level.WARNING, this + ": can't serialize session", e);
    }
  }
View Full Code Here

    if (cache == null)
      return null;

    try {
      TempOutputStream os = new TempOutputStream();

      if (cache.get(id, os)) {
        InputStream is = os.getInputStream();

        StringWriter writer = new StringWriter();

        HessianDebugInputStream dis
          = new HessianDebugInputStream(is, new PrintWriter(writer));

        while (dis.read() >= 0) {
        }

        return writer.toString();
      }

      os.close();
    } catch (Exception e) {
      log.log(Level.FINE, e.toString(), e);

      return e.toString();
    }
View Full Code Here

  final public HashKey writeData(HashKey oldValueHash,
                                 Object value,
                                 CacheSerializer serializer)
  {
    TempOutputStream os = null;

    try {
      os = new TempOutputStream();

      Sha256OutputStream mOut = new Sha256OutputStream(os);
      DeflaterOutputStream gzOut = new DeflaterOutputStream(mOut);

      serializer.serialize(value, gzOut);

      gzOut.finish();
      mOut.close();

      byte[] hash = mOut.getDigest();

      HashKey valueHash = new HashKey(hash);

      if (valueHash.equals(oldValueHash))
        return valueHash;

      int length = os.getLength();

      StreamSource source = new StreamSource(os);
      if (! getDataBacking().saveData(valueHash, source, length)) {
        throw new IllegalStateException(L.l("Can't save the data '{0}'",
                                       valueHash));
      }

      return valueHash;
    } catch (Exception e) {
      throw new RuntimeException(e);
    } finally {
      if (os != null)
        os.close();
    }
  }
View Full Code Here

  @Override
  final public byte[] calculateValueHash(Object value,
                                          CacheConfig config)
  {
    CacheSerializer serializer = config.getValueSerializer();
    TempOutputStream os = null;
   
    try {
      os = new TempOutputStream();

      Sha256OutputStream mOut = new Sha256OutputStream(os);
      DeflaterOutputStream gzOut = new DeflaterOutputStream(mOut);

      serializer.serialize(value, gzOut);

      gzOut.finish();
      mOut.close();

      byte[] hash = mOut.getDigest();

      return hash;
    } catch (Exception e) {
      throw new RuntimeException(e);
    } finally {
      if (os != null)
        os.close();
    }
  }
View Full Code Here

  final protected HashKey writeData(HashKey oldValueHash,
                                    InputStream is)
    throws IOException
  {
    TempOutputStream os = null;

    try {
      os = new TempOutputStream();

      Sha256OutputStream mOut = new Sha256OutputStream(os);

      WriteStream out = Vfs.openWrite(mOut);

      out.writeStream(is);

      out.close();

      mOut.close();

      byte[] hash = mOut.getDigest();

      HashKey valueHash = new HashKey(hash);

      if (valueHash.equals(oldValueHash)) {
        os.destroy();
        return valueHash;
      }

      int length = os.getLength();
      StreamSource source = new StreamSource(os);

      if (! getDataBacking().saveData(valueHash, source, length))
        throw new RuntimeException(L.l("Can't save the data '{0}'",
                                       valueHash));

      return valueHash;
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw new RuntimeException(e);
    } finally {
      if (os != null)
        os.close();
    }
  }
View Full Code Here

      Cipher cipher = initCipher(cookie, Cipher.ENCRYPT_MODE);
     
      SelfEncryptedCookie cookieObj
        = new SelfEncryptedCookie(cookie, createTime);

      TempOutputStream tos = new TempOutputStream();
      Hessian2Output hOut = new Hessian2Output(tos);

      hOut.writeObject(cookieObj);

      hOut.close();

      TempOutputStream cipherOut = new TempOutputStream();
      CipherOutputStream cOut
        = new CipherOutputStream(cipherOut, cipher);

      tos.writeToStream(cOut);
      tos.destroy();

      cOut.close();

      byte []encryptedData = cipherOut.toByteArray();

      cipherOut.destroy();

      return encryptedData;
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
View Full Code Here

        Node data = XPath.find("data", node);

        if (data != null) {
          data = data.getFirstChild();

          TempOutputStream os = new TempOutputStream();

          XmlPrinter printer = new XmlPrinter(os);

          printer.printXml(data);

          os.close();

          long length = os.getLength();

          if (length == 0)
            continue;

          InputStream is = os.openInputStreamNoFree();

          String sha1 = _deployClient.calculateFileDigest(is, length);

          _deployClient.sendFile(sha1, length, os.openInputStream());

          _deployClient.deploy(tag);

          _deployClient.addDeployFile(tag, name, sha1);
        }
View Full Code Here

  public String addBlob(InputStream is, long length)
    throws IOException
  {
    String type = "blob";

    TempOutputStream os = new TempOutputStream();

    String hash = GitSystem.writeData(os, type, is, length);

    writeRawGitFile(hash, os.openInputStream());
   
    return hash;
  }
View Full Code Here

TOP

Related Classes of com.caucho.vfs.TempOutputStream

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.