Package com.caucho.vfs

Examples of com.caucho.vfs.WriteStream


  void closeImpl()
  {
    ReadStream is = _is;
    _is = null;

    WriteStream os = _os;
    _os = null;

    try {
      if (is != null)
        is.close();
    } catch (Throwable e) {
      log.log(Level.FINER, e.toString(), e);
    }

    try {
      if (os != null)
        os.close();
    } catch (Throwable e) {
      log.log(Level.FINER, e.toString(), e);
    }

    if (is != null) {
View Full Code Here


    }

    public void writeToStream(OutputStream os)
      throws IOException
    {
      WriteStream writeStream = Vfs.openWrite(os);

      try {
        writeStream.print(_data);
      }
      finally {
        writeStream.close();
      }
    }
View Full Code Here

  public void close()
  {
    ReadStream is = _is;
    _is = null;
   
    WriteStream os = _os;
    _os = null;

    _in.close();

    if (os != null) {
      try {
        os.close();
      } catch (IOException e) {
      }
    }

    if (is != null) {
View Full Code Here

    HttpServletResponseImpl response = _request.getResponseFacade();

    int statusCode = response.getStatus();
    String statusMessage = response.getStatusMessage();

    WriteStream os = _req.getWriteStream();

    os.print("Status: ");
    os.print(statusCode);
    os.print(' ');
    os.print(statusMessage);
    os.print("\r\n");

    CharBuffer cb = _cb;

    if (statusCode >= 400) {
      removeHeader("ETag");
      removeHeader("Last-Modified");
    }
    else if (response.isNoCache()) {
      removeHeader("ETag");
      removeHeader("Last-Modified");

      setHeader("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");

      os.print("Cache-Control: no-cache\r\n");
    }
    else if (response.isPrivateCache()) {
      os.print("Cache-Control: private\r\n");
    }

    int size = _headerKeys.size();
    for (int i = 0; i < size; i++) {
      String key = (String) _headerKeys.get(i);
      String value = (String) _headerValues.get(i);

      os.print(key);
      os.print(": ");
      os.print(value);
      os.print("\r\n");
    }

    long now = Alarm.getCurrentTime();
    ArrayList<Cookie> cookiesOut = response.getCookies();

    if (cookiesOut != null) {
      size = cookiesOut.size();
      for (int i = 0; i < size; i++) {
        Cookie cookie = cookiesOut.get(i);
        int cookieVersion = cookie.getVersion();

        fillCookie(cb, cookie, now, 0, false);

        os.print("Set-Cookie: ");
        os.print(cb);
        os.print("\r\n");

        if (cookieVersion > 0) {
          fillCookie(cb, cookie, now, cookieVersion, true);

          os.print("Set-Cookie2: ");
          os.print(cb);
          os.print("\r\n");
        }
      }
    }

    String contentType = response.getContentTypeImpl();
    String charEncoding = response.getCharacterEncodingImpl();

    if (contentType != null) {
      if (charEncoding != null) {
        os.print("Content-Type: ");
        os.print(contentType);
        os.print("; charset=");
        os.print(charEncoding);
        os.print("\r\n");
      }
      else {
        os.print("Content-Type: ");
        os.print(contentType);
        os.print("\r\n");
      }
    }

    os.print("\r\n");

    return false;
  }
View Full Code Here

  }

  protected void writeResponse(OutputStream out, Object result)
    throws IOException, RestException
  {
    WriteStream ws = Vfs.openWrite(out);

    try {
      XMLStreamWriterImpl writer = new XMLStreamWriterImpl(ws);
     
      _marshaller.marshal(result, writer);
    }
    catch (JAXBException e) {
      throw new RuntimeException(e);
    }
    finally {
      ws.close();
    }
  }
View Full Code Here

  }

  public static WriteStream openWrite(Path p)
    throws IOException
  {
    WriteStream s = p.openWrite();
    Exit.addExit(exitOutputStream, s);
    return s;
  }
View Full Code Here

  }

  public static WriteStream openAppend(Path p)
    throws IOException
  {
    WriteStream s = p.openAppend();
    Exit.addExit(exitOutputStream, s);
    return s;
  }
View Full Code Here

  }

  public static void write(Path path, Call call, int length)
    throws Throwable
  {
    WriteStream s = path.openWrite();

    try {
      for (int i = 0; i < length; i++) {
        String string = call.getArgString(i, length);

        s.print(string);
      }
    } finally {
      s.close();
    }
  }
View Full Code Here

  }

  public static void writeln(Path path, Call call, int length)
  throws Throwable
  {
    WriteStream s = path.openWrite();

    try {
      for (int i = 0; i < length; i++) {
        String string = call.getArgString(i, length);

        s.print(string);
      }

      s.print('\n');
    } finally {
      s.close();
    }
  }
View Full Code Here

  }

  public static void writeStream(Path path, InputStream is)
  throws Throwable
  {
    WriteStream s = path.openWrite();

    try {
      s.writeStream(is);
    } finally {
      s.close();
    }
  }
View Full Code Here

TOP

Related Classes of com.caucho.vfs.WriteStream

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.