Package com.caucho.vfs

Examples of com.caucho.vfs.WriteStream


   */
  private void openLog()
  {
    closeLogStream();

    WriteStream os = _os;
    _os = null;

    IoUtil.close(os);

    Path path = getPath();
View Full Code Here


                 e);
    }

    try {
      if (path.exists()) {
        WriteStream os = null;
        OutputStream out = null;

        // *.gz and *.zip are copied.  Others are just renamed
        if (savedName.endsWith(".gz")) {
          os = savedPath.openWrite();
          out = new GZIPOutputStream(os);
        }
        else if (savedName.endsWith(".zip")) {
          os = savedPath.openWrite();

          ZipOutputStream zip = new ZipOutputStream(os);
          String entryName = savedName.substring(0, savedName.length() - 4);
          ZipEntry entry = new ZipEntry(entryName);
          zip.putNextEntry(entry);

          out = zip;
        }

        if (out != null) {
          try {
            path.writeToStream(out);
          } finally {
            try {
              out.close();
            } catch (Exception e) {
              // can't log in log rotation routines
            }

            try {
              if (out != os)
                os.close();
            } catch (Exception e) {
              // can't log in log rotation routines
            }
          }
        }
View Full Code Here

   * Tries to close the log.
   */
  private void closeLogStream()
  {
    try {
      WriteStream os = _os;
      _os = null;

      if (os != null)
        os.close();
    } catch (Throwable e) {
      // can't log in log routines
    }

    try {
      WriteStream zipOut = _zipOut;
      _zipOut = null;

      if (zipOut != null)
        zipOut.close();
    } catch (Throwable e) {
      // can't log in log routines
    }
  }
View Full Code Here

    throws IOException
  {
    CharBuffer line = CharBuffer.allocate();
    String topId = null;
    int count = 1;
    WriteStream ws = null;
    IntMap messages = new IntMap();

    try {
      while (true) {
        do {
          line.clear();
          if (! is.readLine(line)) {
            if (ws != null)
              ws.println("</message>");
            return false;
          }
          if (ws != null && ! line.startsWith("From ")) {
            for (int i = 0; i < line.length(); i++) {
              char ch = line.charAt(i);
              if (ch == '<')
                ws.print("&lt;");
              else
                ws.print(ch);
            }
            ws.println();
          }
        } while (! line.startsWith("From "));

        if (ws != null) {
          ws.println("</message>");
          ws.close();
          ws = null;
        }


        String date = null;
        String subject = null;
        String from = null;
        String id = null;
        String references = null;

        do {
          line.clear();
          if (! is.readLine(line))
            return false;
          if (line.length() == 0)
            break;

          String lower = line.toString().toLowerCase(Locale.ENGLISH);

          if (lower.startsWith("subject: ")) {
            subject = line.substring("subject: ".length()).trim();

            if (subject.toLowerCase(Locale.ENGLISH).startsWith("re:"))
              subject = subject.substring(3).trim();
          }
          else if (lower.startsWith("from: ")) {
            from = line.substring("from: ".length());
          }
          else if (lower.startsWith("date: ")) {
            date = line.substring("from: ".length());
          }
        } while (line.length() > 0);

        int index = messages.get(subject);

        if (index >= 0) {
          ws = dst.lookup("" + index + ".xtp").openAppend();
        }
        else {
          if (subject != null && ! subject.equals(""))
            messages.put(subject, count);

          ws = dst.lookup("" + count++ + ".xtp").openWrite();
          ws.println("<title>" + subject + "</title>");
        }
        ws.println("<em>" + from + "</em>");
        ws.println("<date>" + date + "</date>");
        ws.println("<message>");
      }
    } finally {
      if (ws != null)
        ws.close();
    }
  }
View Full Code Here

  }

  public ESBase call(Call eval, int length) throws Throwable
  {
    ESBase evalThis = eval.getArg(-1);
    WriteStream stream = null;

    try {
      stream = (WriteStream) evalThis.toJavaObject();
    } catch (Exception e) {
    }
View Full Code Here

  }

  private static WriteStream getWriteStream(Call eval) throws Throwable
  {
    ESBase evalThis = eval.getArg(-1);
    WriteStream stream = null;

    try {
      stream = (WriteStream) evalThis.toJavaObject();
    } catch (Exception e) {
    }
View Full Code Here

    return stream;
  }

  static public ESBase write(Call eval, int length) throws Throwable
  {
    WriteStream stream = getWriteStream(eval);

    try {
      for (int i = 0; i < length; i++)
        stream.print(eval.getArg(i).toString());
    } catch (IOException e) {
      return ESBoolean.FALSE;
    }

    return eval.getArg(-1);
View Full Code Here

    return eval.getArg(-1);
  }

  static public ESBase writeln(Call eval, int length) throws Throwable
  {
    WriteStream stream = getWriteStream(eval);

    try {
      for (int i = 0; i < length; i++)
        stream.print(eval.getArg(i).toString());
      stream.println();
    } catch (IOException e) {
      return ESBoolean.FALSE;
    }

    return eval.getArg(-1);
View Full Code Here

    return eval.getArg(-1);
  }

  static public ESBase flush(Call eval, int length) throws Throwable
  {
    WriteStream stream = getWriteStream(eval);

    try {
      stream.flush();
    } catch (IOException e) {
      return ESBoolean.FALSE;
    }

    return eval.getArg(-1);
View Full Code Here

    return eval.getArg(-1);
  }

  static public ESBase close(Call eval, int length) throws Throwable
  {
    WriteStream stream = getWriteStream(eval);

    try {
      stream.close();
    } catch (IOException e) {
      return ESBoolean.FALSE;
    }

    return eval.getArg(-1);
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.