/** * 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 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"); }
/** * 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); } }
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); } } }
private bool setLobParameter(Env env, int index, Value value) { if (_preparedStmt == null) { return(false); } try { if (value == null || value.isNull()) { _preparedStmt.setObject(index, null); } else if (value.isString()) { _preparedStmt.setBinaryStream(index, value.toInputStream(), value.length()); } else { InputStream inputStream = value.toInputStream(); if (inputStream == null) { env.warning(L.l("type {0} ({1}) for parameter index {2} cannot be used for lob", value.getType(), value.getClass(), index)); return(false); } int length = -1; if (value instanceof FileReadValue) { length = (int)((FileReadValue)value).getLength(); if (length <= 0) { length = -1; } } if (length < 0) { TempBuffer tempBuffer = TempBuffer.allocate(); try { byte[] bytes = new byte[1024]; int len; while ((len = inputStream.read(bytes, 0, 1024)) != -1) { tempBuffer.write(bytes, 0, len); } } catch (IOException e) { env.warning(e); return(false); } TempReadStream tempReadStream = new TempReadStream(tempBuffer); tempReadStream.setFreeWhenDone(true); _preparedStmt.setBinaryStream(index, new ReadStream(tempReadStream), tempBuffer.getLength()); } else { _preparedStmt.setBinaryStream(index, inputStream, length); } } } catch (SQLException e) { setError(env, e); return(false); } return(true); }