@Override public <X> byte[] wrap(X value, WrapperOptions options) { if ( value == null ) { return null; } if ( Byte[].class.isInstance( value ) ) { return unwrapBytes( (Byte[]) value ); } if ( byte[].class.isInstance( value ) ) { return (byte[]) value; } if ( InputStream.class.isInstance( value ) ) { return DataHelper.extractBytes( (InputStream) value ); } if ( Blob.class.isInstance( value ) || DataHelper.isNClob( value.getClass() ) ) { try { return DataHelper.extractBytes( ( (Blob) value ).getBinaryStream() ); } catch (SQLException e) { throw new HibernateException( "Unable to access lob stream", e ); } } throw unknownWrap( value.getClass() ); }
@Override public byte[] getBytes() { if ( bytes == null ) { bytes = DataHelper.extractBytes( stream ); } return bytes; }
@Override public String asString() { if ( string == null ) { string = DataHelper.extractString( reader ); } return string; }
private static String extractString(Object value) { if (value == null) { return null; } if (value instanceof String) { return (String) value; } if (value instanceof Reader) { return DataHelper.extractString((Reader) value); } if (value instanceof Clob) { return DataHelper.extractString((Clob) value); } return null; }
@Override public <X> X unwrap(BufferedContent value, Class<X> type, WrapperOptions options) { if ( value == null ) { return null; } if ( BufferedContent.class.isAssignableFrom(type)){ return (X) value; } if ( BinaryStream.class.isAssignableFrom(type)) { return (X) new BinaryStreamImpl(DataHelper.extractBytes(value.getInputStream())); } throw unknownUnwrap( type ); }
@Override public String toString(BufferedContent value) { final byte[] bytes; bytes = DataHelper.extractBytes( value.getInputStream()); return PrimitiveByteArrayTypeDescriptor.INSTANCE.toString( bytes ); }