1 29 30 package com.caucho.quercus.lib.file; 31 32 import com.caucho.quercus.QuercusModuleException; 33 import com.caucho.quercus.env.BooleanValue; 34 import com.caucho.quercus.env.Value; 35 import com.caucho.vfs.TempBuffer; 36 37 import java.io.IOException ; 38 import java.io.InputStream ; 39 import java.io.OutputStream ; 40 41 44 abstract public class AbstractBinaryOutput 45 extends OutputStream 46 implements BinaryOutput 47 { 48 private int lockedShared = 0; 49 private boolean lockedExclusive = false; 50 51 54 public OutputStream getOutputStream() 55 { 56 return this; 57 } 58 59 62 public int write(InputStream is, int length) 63 { 64 int writeLength = 0; 65 66 TempBuffer tb = TempBuffer.allocate(); 67 byte []buffer = tb.getBuffer(); 68 69 try { 70 while (length > 0) { 71 int sublen; 72 73 if (length < buffer.length) 74 sublen = length; 75 else 76 sublen = buffer.length; 77 78 sublen = is.read(buffer, 0, sublen); 79 80 if (sublen < 0) 81 break; 82 83 write(buffer, 0, sublen); 84 85 writeLength += sublen; 86 length -= sublen; 87 } 88 89 return writeLength; 90 } catch (IOException e) { 91 throw new QuercusModuleException(e); 92 } finally { 93 TempBuffer.free(tb); 94 } 95 } 96 97 100 public void print(char v) 101 throws IOException 102 { 103 write((byte) v); 104 } 105 106 109 public void print(String v) 110 throws IOException 111 { 112 for (int i = 0; i < v.length(); i++) 113 write(v.charAt(i)); 114 } 115 116 119 public void flush() 120 throws IOException 121 { 122 } 123 124 125 128 public void closeWrite() 129 { 130 close(); 131 } 132 133 136 public void close() 137 { 138 } 139 140 143 public boolean isEOF() 144 { 145 return false; 146 } 147 148 151 public long getPosition() 152 { 153 return 0; 154 } 155 156 159 public boolean setPosition(long offset) 160 { 161 return false; 162 } 163 164 public String getResourceType() 165 { 166 return "stream"; 167 } 168 169 public Value stat() 170 { 171 return BooleanValue.FALSE; 172 } 173 } 174 175 | Popular Tags |