KickJava   Java API By Example, From Geeks To Geeks.

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


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 Emil Ong
28  */

29
30 package com.caucho.quercus.lib.file;
31
32 import com.caucho.quercus.env.BooleanValue;
33 import com.caucho.quercus.env.Env;
34 import com.caucho.quercus.env.LongValue;
35 import com.caucho.quercus.env.StringValue;
36 import com.caucho.quercus.env.Value;
37 import com.caucho.util.L10N;
38
39 import java.io.IOException JavaDoc;
40
41 public class PhpProtocolWrapper extends ProtocolWrapper {
42   private static final L10N L = new L10N(PhpProtocolWrapper.class);
43
44   public PhpProtocolWrapper()
45   {
46   }
47
48   public BinaryStream fopen(Env env, StringValue path, StringValue mode,
49                             LongValue options)
50   {
51     if (path.toString().equals("php://output")) {
52       return new PhpBinaryOutput(env);
53     } else {
54       env.warning(L.l("{0} is an unsupported or unknown path for this protocol",
55                       path.toString()));
56
57       return null;
58     }
59   }
60
61   public Value opendir(Env env, StringValue path, LongValue flags)
62   {
63     env.warning(L.l("opendir not supported by protocol"));
64
65     return BooleanValue.FALSE;
66   }
67
68   public boolean unlink(Env env, StringValue path)
69   {
70     env.warning(L.l("unlink not supported by protocol"));
71
72     return false;
73   }
74
75   public boolean rename(Env env, StringValue path_from, StringValue path_to)
76   {
77     env.warning(L.l("rename not supported by protocol"));
78
79     return false;
80   }
81
82   public boolean mkdir(Env env,
83                        StringValue path, LongValue mode, LongValue options)
84   {
85     env.warning(L.l("mkdir not supported by protocol"));
86
87     return false;
88   }
89
90   public boolean rmdir(Env env, StringValue path, LongValue options)
91   {
92     env.warning(L.l("rmdir not supported by protocol"));
93
94     return false;
95   }
96
97   public Value url_stat(Env env, StringValue path, LongValue flags)
98   {
99     env.warning(L.l("stat not supported by protocol"));
100
101     return BooleanValue.FALSE;
102   }
103
104   private class PhpBinaryOutput extends AbstractBinaryOutput {
105     private Env _env;
106
107     public PhpBinaryOutput(Env env)
108     {
109       _env = env;
110     }
111
112     /**
113      * Writes a buffer.
114      */

115     public void write(byte []buffer, int offset, int length)
116       throws IOException JavaDoc
117     {
118       _env.getOut().write(buffer, offset, length);
119     }
120
121     public void write(int b)
122       throws IOException JavaDoc
123     {
124       _env.getOut().write(b);
125     }
126   }
127 }
128
129
Popular Tags