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 Emil Ong
028: */
029:
030: package com.caucho.quercus.lib.file;
031:
032: import com.caucho.quercus.env.BooleanValue;
033: import com.caucho.quercus.env.Env;
034: import com.caucho.quercus.env.LongValue;
035: import com.caucho.quercus.env.StringValue;
036: import com.caucho.quercus.env.Value;
037: import com.caucho.util.L10N;
038:
039: import java.io.IOException;
040:
041: public class PhpProtocolWrapper extends ProtocolWrapper {
042: private static final L10N L = new L10N(PhpProtocolWrapper.class);
043:
044: public PhpProtocolWrapper() {
045: }
046:
047: public BinaryStream fopen(Env env, StringValue path,
048: StringValue mode, LongValue options) {
049: if (path.toString().equals("php://output")) {
050: return new PhpBinaryOutput(env);
051: } else {
052: env
053: .warning(L
054: .l(
055: "{0} is an unsupported or unknown path for this protocol",
056: path.toString()));
057:
058: return null;
059: }
060: }
061:
062: public Value opendir(Env env, StringValue path, LongValue flags) {
063: env.warning(L.l("opendir not supported by protocol"));
064:
065: return BooleanValue.FALSE;
066: }
067:
068: public boolean unlink(Env env, StringValue path) {
069: env.warning(L.l("unlink not supported by protocol"));
070:
071: return false;
072: }
073:
074: public boolean rename(Env env, StringValue path_from,
075: StringValue path_to) {
076: env.warning(L.l("rename not supported by protocol"));
077:
078: return false;
079: }
080:
081: public boolean mkdir(Env env, StringValue path, LongValue mode,
082: LongValue options) {
083: env.warning(L.l("mkdir not supported by protocol"));
084:
085: return false;
086: }
087:
088: public boolean rmdir(Env env, StringValue path, LongValue options) {
089: env.warning(L.l("rmdir not supported by protocol"));
090:
091: return false;
092: }
093:
094: public Value url_stat(Env env, StringValue path, LongValue flags) {
095: env.warning(L.l("stat not supported by protocol"));
096:
097: return BooleanValue.FALSE;
098: }
099:
100: private class PhpBinaryOutput extends AbstractBinaryOutput {
101: private Env _env;
102:
103: public PhpBinaryOutput(Env env) {
104: _env = env;
105: }
106:
107: /**
108: * Writes a buffer.
109: */
110: public void write(byte[] buffer, int offset, int length)
111: throws IOException {
112: _env.getOut().write(buffer, offset, length);
113: }
114:
115: public void write(int b) throws IOException {
116: _env.getOut().write(b);
117: }
118: }
119: }
|