001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.quercus.lib.file;
031:
032: import com.caucho.quercus.env.UnicodeBuilderValue;
033: import com.caucho.quercus.env.StringValue;
034: import com.caucho.quercus.resources.StreamResource;
035: import com.caucho.vfs.Path;
036:
037: import java.io.IOException;
038: import java.io.OutputStream;
039:
040: /**
041: * Represents a Quercus open file
042: */
043: public class FileValue extends StreamResource {
044: private Path _path;
045:
046: public FileValue(Path path) {
047: _path = path;
048: }
049:
050: /**
051: * Returns the path.
052: */
053: public Path getPath() {
054: return _path;
055: }
056:
057: /**
058: * Reads a character from a file, returning -1 on EOF.
059: */
060: public int read() throws IOException {
061: return -1;
062: }
063:
064: /**
065: * Reads a line from a file, returning null.
066: */
067: public StringValue readLine() throws IOException {
068: UnicodeBuilderValue sb = new UnicodeBuilderValue();
069:
070: int ch;
071:
072: while ((ch = read()) >= 0) {
073: sb.append((char) ch);
074:
075: if (ch == '\n')
076: return sb;
077: // XXX: issues with mac
078: }
079:
080: if (sb.length() > 0)
081: return sb;
082: else
083: return null;
084: }
085:
086: /**
087: * Read a maximum of <i>length</i> bytes from the file and write
088: * them to the outputStream.
089: *
090: * @param os the {@link OutputStream}
091: * @param length the maximum number of bytes to read
092: */
093: public void writeToStream(OutputStream os, int length)
094: throws IOException {
095: }
096:
097: /**
098: * Prints a string to a file.
099: */
100: public void print(String v) throws IOException {
101: }
102:
103: /**
104: * Closes the file.
105: */
106: public void close() {
107: }
108:
109: /**
110: * Converts to a string.
111: * @param env
112: */
113: public String toString() {
114: return "File[" + _path + "]";
115: }
116: }
|