KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > lib > file > FileValue


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.quercus.lib.file;
31
32 import com.caucho.quercus.env.StringBuilderValue;
33 import com.caucho.quercus.env.StringValue;
34 import com.caucho.quercus.resources.StreamResource;
35 import com.caucho.vfs.Path;
36
37 import java.io.IOException JavaDoc;
38 import java.io.OutputStream JavaDoc;
39
40 /**
41  * Represents a Quercus open file
42  */

43 public class FileValue extends StreamResource {
44   private Path _path;
45
46   public FileValue(Path path)
47   {
48     _path = path;
49   }
50
51   /**
52    * Returns the path.
53    */

54   public Path getPath()
55   {
56     return _path;
57   }
58
59   /**
60    * Reads a character from a file, returning -1 on EOF.
61    */

62   public int read()
63     throws IOException JavaDoc
64   {
65     return -1;
66   }
67
68   /**
69    * Reads a line from a file, returning null.
70    */

71   public StringValue readLine()
72     throws IOException JavaDoc
73   {
74     StringBuilderValue sb = new StringBuilderValue();
75
76     int ch;
77
78     while ((ch = read()) >= 0) {
79       sb.append((char) ch);
80
81       if (ch == '\n')
82     return sb;
83       // XXX: issues with mac
84
}
85
86     if (sb.length() > 0)
87       return sb;
88     else
89       return null;
90   }
91
92   /**
93    * Read a maximum of <i>length</i> bytes from the file and write
94    * them to the outputStream.
95    *
96    * @param os the {@link OutputStream}
97    * @param length the maximum number of bytes to read
98    */

99   public void writeToStream(OutputStream JavaDoc os, int length)
100     throws IOException JavaDoc
101   {
102   }
103
104   /**
105    * Prints a string to a file.
106    */

107   public void print(String JavaDoc v)
108     throws IOException JavaDoc
109   {
110   }
111
112   /**
113    * Closes the file.
114    */

115   public void close()
116   {
117   }
118
119   /**
120    * Converts to a string.
121    * @param env
122    */

123   public String JavaDoc toString()
124   {
125     return "File[" + _path + "]";
126   }
127 }
128
129
Popular Tags