Package com.caucho.vfs

Examples of com.caucho.vfs.TempStream


                        @Optional("1") int encodingMode)
  {
    TempBuffer tempBuf = TempBuffer.allocate();
    byte[] buffer = tempBuf.getBuffer();

    TempStream ts = new TempStream();
    StreamImplOutputStream out = new StreamImplOutputStream(ts);

    ZlibOutputStream gzOut = null;

    try {
      gzOut = new ZlibOutputStream(out, level,
                                   Deflater.DEFAULT_STRATEGY,
                                   encodingMode);

      int len;
      while ((len = is.read(buffer, 0, buffer.length)) > 0) {
        gzOut.write(buffer, 0, len);
      }
      gzOut.close();

      StringValue sb = env.createBinaryBuilder();
      for (TempBuffer ptr = ts.getHead(); ptr != null; ptr = ptr.getNext())
        sb.append(ptr.getBuffer(), 0, ptr.getLength());

      return sb;
    } catch(IOException e) {
      throw QuercusModuleException.create(e);
    } finally {
      TempBuffer.free(tempBuf);

      ts.destroy();

      if (gzOut != null)
        gzOut.close();
    }
  }
View Full Code Here


  public void write(ByteCodeWriter out)
    throws IOException
  {
    out.writeUTF8Const(getName());

    TempStream ts = new TempStream();
    ts.openWrite();
    WriteStream ws = new WriteStream(ts);
    ByteCodeWriter o2 = new ByteCodeWriter(ws, out.getJavaClass());
   
    o2.writeShort(_maxStack);
    o2.writeShort(_maxLocals);
    o2.writeInt(_code.length);
    o2.write(_code, 0, _code.length);

    o2.writeShort(_exceptions.size());
    for (int i = 0; i < _exceptions.size(); i++) {
      ExceptionItem exn = _exceptions.get(i);

      o2.writeShort(exn.getStart());
      o2.writeShort(exn.getEnd());
      o2.writeShort(exn.getHandler());
      o2.writeShort(exn.getType());
    }

    o2.writeShort(_attributes.size());
    for (int i = 0; i < _attributes.size(); i++) {
      Attribute attr = _attributes.get(i);

      attr.write(o2);
    }
   
    ws.close();
   
    out.writeInt(ts.getLength());
    TempBuffer ptr = ts.getHead();

    for (; ptr != null; ptr = ptr.getNext())
      out.write(ptr.getBuffer(), 0, ptr.getLength());

    ts.destroy();
  }
View Full Code Here

    }
    else if (ch == 0xff) {
      if (_is.read() != 0xd8)
        return false;

      TempStream ts = new TempStream();

      WriteStream ws = new WriteStream(ts);
      ws.write(0xff);
      ws.write(0xd8);
      _is.writeToStream(ws);
      ws.close();

      // XXX: issues with _jpegHead vs ts.openReadAndSaveBuffer()
      _jpegHead = ts.getHead();
      _is.close();

      _is = new ReadStream();
      ts.openRead(_is);

      parseJPEG();

      return true;
    }
View Full Code Here

  public boolean begin_document(@Optional String fileName,
                                @Optional String optList)
    throws IOException
  {
    _tempStream = new TempStream();
    _tempStream.openWrite();
    _os = new WriteStream(_tempStream);

    _out = new PDFWriter(_os);
    _out.beginDocument();
View Full Code Here

  /**
   * Returns the result as a string.
   */
  public Value get_buffer(Env env)
  {
    TempStream ts = _tempStream;
    _tempStream = null;

    if (ts == null)
      return BooleanValue.FALSE;

    StringValue result = env.createBinaryBuilder();
    for (TempBuffer ptr = ts.getHead();
         ptr != null;
         ptr = ptr.getNext()) {
      result.append(ptr.getBuffer(), 0, ptr.getLength());
    }

    ts.destroy();

    return result;
  }
View Full Code Here

  PDFStream(int id)
  {
    _id = id;

    _tempStream = new TempStream();
    _tempStream.openWrite();
    _out.init(_tempStream);

    _procSet = new PDFProcSet();
    _procSet.add("/PDF");
View Full Code Here

   
    try {
      deflater = new Deflater(level, true);

      boolean isFinished = false;
      TempStream out = new TempStream();

      int len;
      while (! isFinished) {
        if (! isFinished && deflater.needsInput()) {
          len = data.read(buffer, 0, buffer.length);

          if (len > 0)
            deflater.setInput(buffer, 0, len);
          else {
            isFinished = true;
            deflater.finish();
          }
        }

        while ((len = deflater.deflate(buffer, 0, buffer.length)) > 0) {
          out.write(buffer, 0, len, false);
        }
      }
      deflater.end();

      return env.createBinaryString(out.getHead());

    } catch (Exception e) {
      throw QuercusModuleException.create(e);
    } finally {
      TempBuffer.free(tempBuf);
View Full Code Here

                        @Optional("1") int encodingMode)
  {
    TempBuffer tempBuf = TempBuffer.allocate();
    byte[] buffer = tempBuf.getBuffer();

    TempStream ts = new TempStream();
    StreamImplOutputStream out = new StreamImplOutputStream(ts);

    ZlibOutputStream gzOut = null;

    try {
      gzOut = new ZlibOutputStream(out, level,
                                   Deflater.DEFAULT_STRATEGY,
                                   encodingMode);

      int len;
      while ((len = is.read(buffer, 0, buffer.length)) > 0) {
        gzOut.write(buffer, 0, len);
      }
      gzOut.close();

      StringValue sb = env.createBinaryBuilder();
      for (TempBuffer ptr = ts.getHead(); ptr != null; ptr = ptr.getNext())
        sb.append(ptr.getBuffer(), 0, ptr.getLength());

      return sb;
    } catch (IOException e) {
      throw QuercusModuleException.create(e);
    } finally {
      TempBuffer.free(tempBuf);

      ts.destroy();

      if (gzOut != null)
        gzOut.close();
    }
  }
View Full Code Here

    return saveToString(env, true);
  }

  private StringValue saveToString(Env env, boolean isHTML)
  {
    TempStream tempStream = new TempStream();

    try {
      tempStream.openWrite();
      WriteStream os = new WriteStream(tempStream);

      saveToStream(os, isHTML);

      os.close();
    }
    catch (IOException ex) {
      tempStream.discard();
      env.warning(ex);
      return null;
    }

    StringValue result = env.createBinaryString(tempStream.getHead());

    tempStream.discard();

    return result;
  }
View Full Code Here

  public void write(ByteCodeWriter out)
    throws IOException
  {
    out.writeUTF8Const(getName());

    TempStream ts = new TempStream();
    ts.openWrite();
    WriteStream ws = new WriteStream(ts);
    ByteCodeWriter o2 = new ByteCodeWriter(ws, out.getJavaClass());

    o2.writeShort(_exceptions.size());
    for (int i = 0; i < _exceptions.size(); i++) {
      String exn = _exceptions.get(i);

      o2.writeClass(exn);
    }
   
    ws.close();
   
    out.writeInt(ts.getLength());
   
    TempBuffer ptr = ts.getHead();

    for (; ptr != null; ptr = ptr.getNext())
      out.write(ptr.getBuffer(), 0, ptr.getLength());

    ts.destroy();
  }
View Full Code Here

TOP

Related Classes of com.caucho.vfs.TempStream

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.