Java Code Examples for org.hibernate.engine.jdbc.internal.BinaryStreamImpl

The following examples show how to use org.hibernate.engine.jdbc.internal.BinaryStreamImpl. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@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 );
}
 
Example 2
Source Project: lams   Source File: ByteArrayTypeDescriptor.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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 );
}
 
Example 3
@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 );
}
 
Example 4
@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 );
}
 
Example 5
Source Project: cosmo   Source File: BufferedContentTypeDescriptor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
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);
}
 
Example 6
Source Project: lams   Source File: BlobTypeDescriptor.java    License: GNU General Public License v2.0 4 votes vote down vote up
@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 );
}
 
Example 7
Source Project: lams   Source File: BlobProxy.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructor used to build {@link Blob} from byte array.
 *
 * @param bytes The byte array
 * @see #generateProxy(byte[])
 */
private BlobProxy(byte[] bytes) {
	binaryStream = new BinaryStreamImpl( bytes );
}
 
Example 8
Source Project: lams   Source File: DataHelper.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Extract a portion of the bytes from the given stream., wrapping them in a new 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 as a stream
 */
public static InputStream subStream(InputStream inputStream, long start, int length) {
	return new BinaryStreamImpl( extractBytes( inputStream, start, length ) );
}