Java 类org.hibernate.engine.jdbc.BinaryStream 实例源码

项目:hibernate-ogm-redis    文件:Base64ByteArrayTypeDescriptor.java   
@Override
@SuppressWarnings( {"unchecked" } )
public <X> X unwrap(byte[] value, Class<X> type, WrapperOptions options) {
    if ( value == null ) {
        return null;
    }
    if ( Byte[].class.isAssignableFrom( type ) ) {
        return (X) value;
    }
    if ( byte[].class.isAssignableFrom( type ) ) {
        return (X) value;
    }
    if ( InputStream.class.isAssignableFrom( type ) ) {
        return (X) new ByteArrayInputStream( value );
    }
    if ( BinaryStream.class.isAssignableFrom( type ) ) {
        return (X) new BinaryStreamImpl( value );
    }
    if ( Blob.class.isAssignableFrom( type ) ) {
        return (X) options.getLobCreator().createBlob( value );
    }

    throw unknownUnwrap( type );
}
项目:lams    文件:PrimitiveByteArrayTypeDescriptor.java   
@SuppressWarnings({ "unchecked" })
public <X> X unwrap(byte[] value, Class<X> type, WrapperOptions options) {
    if ( value == null ) {
        return null;
    }
    if ( byte[].class.isAssignableFrom( type ) ) {
        return (X) value;
    }
    if ( InputStream.class.isAssignableFrom( type ) ) {
        return (X) new ByteArrayInputStream( value );
    }
    if ( BinaryStream.class.isAssignableFrom( type ) ) {
        return (X) new BinaryStreamImpl( value );
    }
    if ( Blob.class.isAssignableFrom( type ) ) {
        return (X) options.getLobCreator().createBlob( value );
    }

    throw unknownUnwrap( type );
}
项目:lams    文件:ByteArrayTypeDescriptor.java   
@SuppressWarnings({ "unchecked" })
@Override
public <X> X unwrap(Byte[] value, Class<X> type, WrapperOptions options) {
    if ( value == null ) {
        return null;
    }
    if ( Byte[].class.isAssignableFrom( type ) ) {
        return (X) value;
    }
    if ( byte[].class.isAssignableFrom( type ) ) {
        return (X) unwrapBytes( value );
    }
    if ( InputStream.class.isAssignableFrom( type ) ) {
        return (X) new ByteArrayInputStream( unwrapBytes( value ) );
    }
    if ( BinaryStream.class.isAssignableFrom( type ) ) {
        return (X) new BinaryStreamImpl( unwrapBytes( value ) );
    }
    if ( Blob.class.isAssignableFrom( type ) ) {
        return (X) options.getLobCreator().createBlob( unwrapBytes( value ) );
    }

    throw unknownUnwrap( type );
}
项目:lams    文件:SerializableTypeDescriptor.java   
@SuppressWarnings({ "unchecked" })
public <X> X unwrap(T value, Class<X> type, WrapperOptions options) {
    if ( value == null ) {
        return null;
    }
    else if ( type.isInstance( value ) ) {
        return (X) value;
    }
    else if ( byte[].class.isAssignableFrom( type ) ) {
        return (X) toBytes( value );
    }
    else if ( InputStream.class.isAssignableFrom( type ) ) {
        return (X) new ByteArrayInputStream( toBytes( value ) );
    }
    else if ( BinaryStream.class.isAssignableFrom( type ) ) {
        return (X) new BinaryStreamImpl( toBytes( value ) );
    }
    else if ( Blob.class.isAssignableFrom( type )) {
        return (X) options.getLobCreator().createBlob( toBytes(value) );
    }

    throw unknownUnwrap( type );
}
项目:hibernate-semantic-query    文件:ByteArrayJavaDescriptor.java   
@SuppressWarnings({ "unchecked" })
@Override
public <X> X unwrap(Byte[] value, Class<X> type, WrapperOptions options) {
    if ( value == null ) {
        return null;
    }
    if ( Byte[].class.isAssignableFrom( type ) ) {
        return (X) value;
    }
    if ( byte[].class.isAssignableFrom( type ) ) {
        return (X) unwrapBytes( value );
    }
    if ( InputStream.class.isAssignableFrom( type ) ) {
        return (X) new ByteArrayInputStream( unwrapBytes( value ) );
    }
    if ( BinaryStream.class.isAssignableFrom( type ) ) {
        return (X) new BinaryStreamImpl( unwrapBytes( value ) );
    }
    if ( Blob.class.isAssignableFrom( type ) ) {
        return (X) options.getLobCreator().createBlob( unwrapBytes( value ) );
    }

    throw unknownUnwrap( type );
}
项目:hibernate-semantic-query    文件:PrimitiveByteArrayJavaDescriptor.java   
@SuppressWarnings({ "unchecked" })
public <X> X unwrap(byte[] value, Class<X> type, WrapperOptions options) {
    if ( value == null ) {
        return null;
    }
    if ( byte[].class.isAssignableFrom( type ) ) {
        return (X) value;
    }
    if ( InputStream.class.isAssignableFrom( type ) ) {
        return (X) new ByteArrayInputStream( value );
    }
    if ( BinaryStream.class.isAssignableFrom( type ) ) {
        return (X) new BinaryStreamImpl( value );
    }
    if ( Blob.class.isAssignableFrom( type ) ) {
        return (X) options.getLobCreator().createBlob( value );
    }

    throw unknownUnwrap( type );
}
项目:hibernate-semantic-query    文件:SerializableJavaDescriptor.java   
@SuppressWarnings({ "unchecked" })
public <X> X unwrap(T value, Class<X> type, WrapperOptions options) {
    if ( value == null ) {
        return null;
    }
    else if ( type.isInstance( value ) ) {
        return (X) value;
    }
    else if ( byte[].class.isAssignableFrom( type ) ) {
        return (X) toBytes( value );
    }
    else if ( InputStream.class.isAssignableFrom( type ) ) {
        return (X) new ByteArrayInputStream( toBytes( value ) );
    }
    else if ( BinaryStream.class.isAssignableFrom( type ) ) {
        return (X) new BinaryStreamImpl( toBytes( value ) );
    }
    else if ( Blob.class.isAssignableFrom( type )) {
        return (X) options.getLobCreator().createBlob( toBytes(value) );
    }

    throw unknownUnwrap( type );
}
项目:perecoder    文件:JsonTypeDescriptor.java   
@SuppressWarnings({"unchecked"})
@Override
public <X> X unwrap(T value, Class<X> type, WrapperOptions options) {
    if (value == null) {
        return null;
    } else if (byte[].class.isAssignableFrom(type)) {
        return (X) toBytes(value);
    } else if (InputStream.class.isAssignableFrom(type)) {
        return (X) new ByteArrayInputStream(toBytes(value));
    } else if (BinaryStream.class.isAssignableFrom(type)) {
        return (X) new BinaryStreamImpl(toBytes(value));
    } else if (Blob.class.isAssignableFrom(type)) {
        return (X) options.getLobCreator().createBlob(toBytes(value));
    }

    throw unknownUnwrap(type);
}
项目:lams    文件:DataHelper.java   
/**
 * Extract a portion of the bytes from the given stream.
 *
 * @param inputStream The stream of bytes.
 * @param start The start position/offset (0-based, per general stream/reader contracts).
 * @param length The amount to extract
 *
 * @return The extracted bytes
 */
public static byte[] extractBytes(InputStream inputStream, long start, int length) {
    if ( BinaryStream.class.isInstance( inputStream ) && Integer.MAX_VALUE > start ) {
        byte[] data = ( (BinaryStream ) inputStream ).getBytes();
        int size = Math.min( length, data.length );
        byte[] result = new byte[size];
        System.arraycopy( data, (int) start, result, 0, size );
        return result;
    }

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream( length );
    try {
        long skipped = inputStream.skip( start );
        if ( skipped != start ) {
            throw new HibernateException( "Unable to skip needed bytes" );
        }
        byte[] buffer = new byte[BUFFER_SIZE];
        int bytesRead = 0;
        while ( true ) {
            int amountRead = inputStream.read( buffer );
            if ( amountRead == -1 ) {
                break;
            }
            outputStream.write( buffer, 0, amountRead );
            if ( amountRead < buffer.length ) {
                // we have read up to the end of stream
                break;
            }
            bytesRead += amountRead;
            if ( bytesRead >= length ) {
                break;
            }
        }
    }
    catch ( IOException ioe ) {
        throw new HibernateException( "IOException occurred reading a binary value", ioe );
    }
    return outputStream.toByteArray();
}
项目:lams    文件:BlobTypeDescriptor.java   
@SuppressWarnings({ "unchecked" })
public <X> X unwrap(Blob value, Class<X> type, WrapperOptions options) {
    if ( value == null ) {
        return null;
    }

    try {
        if ( BinaryStream.class.isAssignableFrom( type ) ) {
            if ( BlobImplementer.class.isInstance( value ) ) {
                // if the incoming Blob is a wrapper, just pass along its BinaryStream
                return (X) ( (BlobImplementer) value ).getUnderlyingStream();
            }
            else {
                // otherwise we need to build a BinaryStream...
                return (X) new BinaryStreamImpl( DataHelper.extractBytes( value.getBinaryStream() ) );
            }
        }
        else if ( byte[].class.isAssignableFrom( type )) {
            if ( BlobImplementer.class.isInstance( value ) ) {
                // if the incoming Blob is a wrapper, just grab the bytes from its BinaryStream
                return (X) ( (BlobImplementer) value ).getUnderlyingStream().getBytes();
            }
            else {
                // otherwise extract the bytes from the stream manually
                return (X) DataHelper.extractBytes( value.getBinaryStream() );
            }
        }
        else if (Blob.class.isAssignableFrom( type )) {
            final Blob blob =  WrappedBlob.class.isInstance( value )
                    ? ( (WrappedBlob) value ).getWrappedBlob()
                    : value;
            return (X) blob;
        }
    }
    catch ( SQLException e ) {
        throw new HibernateException( "Unable to access blob stream", e );
    }

    throw unknownUnwrap( type );
}
项目:lams    文件:BlobTypeDescriptor.java   
@Override
public <X> BasicBinder<X> getBlobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
    return new BasicBinder<X>( javaTypeDescriptor, this ) {
        @Override
        protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
                throws SQLException {
            final BinaryStream binaryStream = javaTypeDescriptor.unwrap(
                    value,
                    BinaryStream.class,
                    options
            );
            st.setBinaryStream( index, binaryStream.getInputStream(), binaryStream.getLength() );
        }
    };
}
项目:hibernate-semantic-query    文件:DataHelper.java   
/**
 * Extract a portion of the bytes from the given stream.
 *
 * @param inputStream The stream of bytes.
 * @param start The start position/offset (0-based, per general stream/reader contracts).
 * @param length The amount to extract
 *
 * @return The extracted bytes
 */
public static byte[] extractBytes(InputStream inputStream, long start, int length) {
    if ( BinaryStream.class.isInstance( inputStream ) && Integer.MAX_VALUE > start ) {
        byte[] data = ( (BinaryStream) inputStream ).getBytes();
        int size = Math.min( length, data.length );
        byte[] result = new byte[size];
        System.arraycopy( data, (int) start, result, 0, size );
        return result;
    }

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream( length );
    try {
        long skipped = inputStream.skip( start );
        if ( skipped != start ) {
            throw new HibernateException( "Unable to skip needed bytes" );
        }
        byte[] buffer = new byte[BUFFER_SIZE];
        int bytesRead = 0;
        while ( true ) {
            int amountRead = inputStream.read( buffer );
            if ( amountRead == -1 ) {
                break;
            }
            outputStream.write( buffer, 0, amountRead );
            if ( amountRead < buffer.length ) {
                // we have read up to the end of stream
                break;
            }
            bytesRead += amountRead;
            if ( bytesRead >= length ) {
                break;
            }
        }
    }
    catch ( IOException ioe ) {
        throw new HibernateException( "IOException occurred reading a binary value", ioe );
    }
    return outputStream.toByteArray();
}
项目:cosmo    文件:BufferedContentTypeDescriptor.java   
@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 );
}
项目:hibernate-semantic-query    文件:BlobJavaDescriptor.java   
@Override
@SuppressWarnings({ "unchecked" })
public <X> X unwrap(Blob value, Class<X> type, WrapperOptions options) {
    if ( value == null ) {
        return null;
    }

    try {
        if ( BinaryStream.class.isAssignableFrom( type ) ) {
            if ( BlobImplementer.class.isInstance( value ) ) {
                // if the incoming Blob is a wrapper, just pass along its BinaryStream
                return (X) ( (BlobImplementer) value ).getUnderlyingStream();
            }
            else {
                // otherwise we need to build a BinaryStream...
                return (X) new BinaryStreamImpl( DataHelper.extractBytes( value.getBinaryStream() ) );
            }
        }
        else if ( byte[].class.isAssignableFrom( type )) {
            if ( BlobImplementer.class.isInstance( value ) ) {
                // if the incoming Blob is a wrapper, just grab the bytes from its BinaryStream
                return (X) ( (BlobImplementer) value ).getUnderlyingStream().getBytes();
            }
            else {
                // otherwise extract the bytes from the stream manually
                return (X) DataHelper.extractBytes( value.getBinaryStream() );
            }
        }
        else if (Blob.class.isAssignableFrom( type )) {
            final Blob blob =  WrappedBlob.class.isInstance( value )
                    ? ( (WrappedBlob) value ).getWrappedBlob()
                    : value;
            return (X) blob;
        }
    }
    catch ( SQLException e ) {
        throw new HibernateException( "Unable to access blob stream", e );
    }

    throw unknownUnwrap( type );
}