/** * Writes the object to the stream */ public void writeObjectNew(PDFWriter out) { long length = _path.getLength(); @out.println("<< /Type /XObject"); @out.println(" /Subtype /Image"); @out.println(" /Width " + _width); @out.println(" /Height " + _height); @out.println(" /ColorSpace /DeviceRGB"); @out.println(" /BitsPerComponent " + _bits); // @out.println(" /Filter /DCTDecode"); @out.println(" /Length " + length); @out.println(">>"); @out.println("stream"); TempBuffer tb = TempBuffer.allocate(); byte [] buffer = tb.getBuffer(); int sublen; InputStream @is = _path.openRead(); while ((sublen = @is.read(buffer, 0, buffer.length)) > 0) { @out.write(buffer, 0, sublen); } @out.println(); @out.println("endstream"); }
public void writeObject(PDFWriter out) { int length = 0; for (TempBuffer ptr = _jpegHead; ptr != null; ptr = ptr.getNext()) { length += ptr.getLength(); } @out.println("<< /Type /XObject"); @out.println(" /Subtype /Image"); @out.println(" /Width " + _width); @out.println(" /Height " + _height); @out.println(" /ColorSpace /DeviceRGB"); @out.println(" /BitsPerComponent " + _bits); @out.println(" /Filter /DCTDecode"); @out.println(" /Length " + length); @out.println(">>"); @out.println("stream"); for (TempBuffer ptr = _jpegHead; ptr != null; ptr = ptr.getNext()) { @out.write(ptr.getBuffer(), 0, ptr.getLength()); } @out.println(); @out.println("endstream"); }
/** * Writes the object to the stream */ public void writeObject(PDFWriter out) { long length = _path.getLength(); @out.println("<< /Type /EmbeddedFile"); @out.println(" /Length " + length); @out.println(">>"); @out.println("stream"); TempBuffer tb = TempBuffer.allocate(); byte [] buffer = tb.getBuffer(); int sublen; InputStream @is = _path.openRead(); while ((sublen = @is.read(buffer, 0, buffer.length)) > 0) { @out.write(buffer, 0, sublen); } @out.println(); @out.println("endstream"); }
/** * Writes to a stream. */ public int write(InputStream @is, int length) { int writeLength = 0; TempBuffer tb = TempBuffer.allocate(); byte [] buffer = tb.getBuffer(); try { while (length > 0) { int sublen; if (length < buffer.length) { sublen = length; } else { sublen = buffer.length; } sublen = @is.read(buffer, 0, sublen); if (sublen < 0) { break; } for (int offset = 0; offset < sublen;) { write(buffer, offset, sublen); if (_writeLength > 0) { offset += _writeLength; } else { return(writeLength); } } writeLength += sublen; length -= sublen; } return(writeLength); } catch (IOException e) { throw new QuercusModuleException(e); } finally { TempBuffer.free(tb); } }
/** * Read length bytes of data from the InputStream * argument and write them to this output stream. */ public int write(InputStream @is, int length) { int writeLength = 0; TempBuffer tb = TempBuffer.allocate(); byte [] buffer = tb.getBuffer(); try { while (length > 0) { int sublen; if (length < buffer.length) { sublen = length; } else { sublen = buffer.length; } sublen = @is.read(buffer, 0, sublen); if (sublen < 0) { break; } write(buffer, 0, sublen); writeLength += sublen; length -= sublen; } return(writeLength); } finally { TempBuffer.free(tb); } }
/** * Returns the buffer contents. */ public Value getContents() { try { _out.flush(); StringValue bb = _env.createBinaryBuilder(_tempStream.getLength()); for (TempBuffer ptr = _tempStream.getHead(); ptr != null; ptr = ptr.getNext()) { bb.append(ptr.getBuffer(), 0, ptr.getLength()); } return(bb); } catch (IOException e) { _env.error(e.ToString(), e); return(BooleanValue.FALSE); } }
public override StringValue encode(StringValue sb, CharSequence str, int start, int end) { CharBuffer in = CharBuffer.wrap(str, start, end); TempBuffer tempBuf = TempBuffer.allocate(); try { ByteBuffer @out = ByteBuffer.wrap(tempBuf.getBuffer()); while (in.hasRemaining()) { CoderResult coder = _encoder.encode(in, @out, false); if (!fill(sb, in, @out, coder)) { return(sb); } @out.clear(); } CoderResult coder = _encoder.encode(in, @out, true); if (!fill(sb, in, @out, coder)) { return(sb); } @out.clear(); coder = _encoder.flush(out); fill(sb, in, @out, coder); return(sb); } finally { TempBuffer.free(tempBuf); } }
void writeData(Env env, OutputStream os) { TempBuffer tempBuf = null; try { tempBuf = TempBuffer.allocate(); byte [] buf = tempBuf.getBuffer(); ReadStream @is = _path.openRead(); int len; while ((len = @is.read(buf, 0, buf.length)) > 0) { os.write(buf, 0, len); } } finally { if (tempBuf != null) { TempBuffer.free(tempBuf); } } }
/** * Returns the result as a string. */ public Value get_buffer(Env env) { TempStream ts = _tempStream; _tempStream = null; if (ts == null) { return(BooleanValue.FALSE); } StringValue result = env.createBinaryBuilder(); for (TempBuffer ptr = ts.getHead(); ptr != null; ptr = ptr.getNext()) { result.append(ptr.getBuffer(), 0, ptr.getLength()); } ts.destroy(); return(result); }