StreamSource

Inheritance: java.lang.Object, com.aspose.imaging.Source

public final class StreamSource extends Source

Represents a stream source.

Constructors

ConstructorDescription
StreamSource(System.IO.Stream stream)Initializes a new instance of the StreamSource class.
StreamSource(InputStream stream)Initializes a new instance of the StreamSource class.
StreamSource(byte[] data)Initializes a new instance of the StreamSource class.
StreamSource(ByteBuffer buffer)Initializes a new instance of the StreamSource class.
StreamSource()Initializes a new instance of the StreamSource class with Null stream.
StreamSource(RandomAccessFile file)Initializes a new instance of the StreamSource class.
StreamSource(RandomAccessFile file, boolean disposeStream)Initializes a new instance of the StreamSource class.
StreamSource(System.IO.Stream stream, boolean disposeStream)Initializes a new instance of the StreamSource class.
StreamSource(InputStream stream, boolean disposeStream)Initializes a new instance of the StreamSource class.

Methods

MethodDescription
getStream()Gets the stream.
getDisposeStream()Gets a value indicating whether stream should be disposed whenever container gets disposed.
getStreamContainer()Gets the stream container.

Example: This example demonstrates how to use StreamSource to create a new Image file (a JPEG type)


//Creates an instance of JpegOptions and set its various properties
com.aspose.imaging.imageoptions.JpegOptions jpegOptions = new com.aspose.imaging.imageoptions.JpegOptions();

//Create an instance of System.IO.Stream
java.io.InputStream stream = new java.io.FileInputStream("C:\\temp\\sample.jpeg");

// Define the source property for the instance of JpegOptions
// Second boolean parameter determines if the Stream is disposed once get out of scope
jpegOptions.setSource(new com.aspose.imaging.sources.StreamSource(stream, true));

// Creates an instance of Image and call Create method with JpegOptions as parameter to initialize the Image object
com.aspose.imaging.Image image = com.aspose.imaging.Image.create(jpegOptions, 500, 500);
try {
    // Do some image processing
} finally {
    image.dispose();
}

StreamSource(System.IO.Stream stream)

public StreamSource(System.IO.Stream stream)

Initializes a new instance of the StreamSource class.

Parameters:

ParameterTypeDescription
streamcom.aspose.ms.System.IO.StreamThe stream to open.

StreamSource(InputStream stream)

public StreamSource(InputStream stream)

Initializes a new instance of the StreamSource class.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamThe stream to open.

StreamSource(byte[] data)

public StreamSource(byte[] data)

Initializes a new instance of the StreamSource class.

Parameters:

ParameterTypeDescription
databyte[]byte array which is stored the image

StreamSource(ByteBuffer buffer)

public StreamSource(ByteBuffer buffer)

Initializes a new instance of the StreamSource class.

Parameters:

ParameterTypeDescription
bufferjava.nio.ByteBufferByteBuffer buffer for storing the image

StreamSource()

public StreamSource()

Initializes a new instance of the StreamSource class with Null stream. This constructor allows to create new images without input stream, images stored only in memory.

StreamSource(RandomAccessFile file)

public StreamSource(RandomAccessFile file)

Initializes a new instance of the StreamSource class.

Parameters:

ParameterTypeDescription
filejava.io.RandomAccessFileThe file to open.

StreamSource(RandomAccessFile file, boolean disposeStream)

public StreamSource(RandomAccessFile file, boolean disposeStream)

Initializes a new instance of the StreamSource class.

Parameters:

ParameterTypeDescription
filejava.io.RandomAccessFileThe file to open.
disposeStreambooleanif set to true the stream will be disposed.

StreamSource(System.IO.Stream stream, boolean disposeStream)

public StreamSource(System.IO.Stream stream, boolean disposeStream)

Initializes a new instance of the StreamSource class.

Parameters:

ParameterTypeDescription
streamcom.aspose.ms.System.IO.StreamThe stream
disposeStreambooleanif set to true the stream will be disposed.

StreamSource(InputStream stream, boolean disposeStream)

public StreamSource(InputStream stream, boolean disposeStream)

Initializes a new instance of the StreamSource class.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamThe stream to open.
disposeStreambooleanif set to true the stream will be disposed.

getStream()

public System.IO.Stream getStream()

Gets the stream.

Returns: com.aspose.ms.System.IO.Stream - The stream.

getDisposeStream()

public boolean getDisposeStream()

Gets a value indicating whether stream should be disposed whenever container gets disposed.

Returns: boolean - true if stream should be disposed; otherwise, false.

getStreamContainer()

public StreamContainer getStreamContainer()

Gets the stream container.

Returns: StreamContainer - the stream container.

Use with caution. You will need to dispose the stream container after retrieval.