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"); }
/** * 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); } }
/** * 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); }
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); }