@Override public Object getObject() { if (type == Value.CLOB) { return getReader(); } return getInputStream(); }
@Override public Reader getReader() { return IOUtils.getBufferedReader(getInputStream()); }
@Override public void set(PreparedStatement prep, int parameterIndex) throws SQLException { long p = getPrecision(); if (p > Integer.MAX_VALUE || p <= 0) { p = -1; } if (type == Value.BLOB) { prep.setBinaryStream(parameterIndex, getInputStream(), (int) p); } else { prep.setCharacterStream(parameterIndex, getReader(), (int) p); } }
@Override public Value convertPrecision(long precision, boolean force) { if (this.precision <= precision) { return this; } ValueLobDb lob; if (type == CLOB) { lob = ValueLobDb.createTempClob(getReader(), precision); } else { lob = ValueLobDb.createTempBlob(getInputStream(), precision); } return lob; }
@Override public byte[] getBytesNoCopy() { if (type == CLOB) { // convert hex to string return super.getBytesNoCopy(); } if (small != null) { return small; } try { return IOUtils.readBytesAndClose(getInputStream(), Integer.MAX_VALUE); } catch (IOException e) { throw DbException.convertIOException(e, toString()); } }
@Override public String getString() { int len = precision > Integer.MAX_VALUE || precision == 0 ? Integer.MAX_VALUE : (int) precision; try { if (type == Value.CLOB) { if (small != null) { return new String(small, Constants.UTF8); } return IOUtils.readStringAndClose(getReader(), len); } byte[] buff; if (small != null) { buff = small; } else { buff = IOUtils.readBytesAndClose(getInputStream(), len); } return StringUtils.convertBytesToHex(buff); } catch (IOException e) { throw DbException.convertIOException(e, toString()); } }
/** * Convert a lob to another data type. The data is fully read in memory * except when converting to BLOB or CLOB. * * @param t the new type * @return the converted value */ @Override public Value convertTo(int t) { if (t == type) { return this; } else if (t == Value.CLOB) { if (small != null) { return ValueLobDb.createSmallLob(t, small); } else { return ValueLobDb.createTempClob(getReader(), -1); } } else if (t == Value.BLOB) { if (small != null) { return ValueLobDb.createSmallLob(t, small); } else { return ValueLobDb.createTempBlob(getInputStream(), -1); } } return super.convertTo(t); }