public abstract class DataStreamSupporter extends DisposableObject
The data stream container.
Modifier and Type | Method and Description |
---|---|
abstract void |
cacheData()
Caches the data and ensures no additional data loading will be performed from the underlying
DataStreamSupporter.DataStreamContainer . |
StreamContainer |
getDataStreamContainer()
Gets the object's data stream.
|
abstract boolean |
isCached()
Gets a value indicating whether object's data is cached currently and no data reading is required.
|
void |
save()
Saves the object's data to the current
DataStreamSupporter . |
void |
save(OutputStream stream)
Saves the object's data to the specified stream.
|
void |
save(RandomAccessFile file)
Saves the object's data to the specified stream.
|
void |
save(String filePath)
Saves the object's data to the specified file location.
|
void |
save(String filePath,
boolean overWrite)
Saves the object's data to the specified file location.
|
close, dispose, getDisposed
public StreamContainer getDataStreamContainer()
Gets the object's data stream.
public abstract boolean isCached()
Gets a value indicating whether object's data is cached currently and no data reading is required.
public abstract void cacheData()
Caches the data and ensures no additional data loading will be performed from the underlying DataStreamSupporter.DataStreamContainer
.
The following example shows how image caching affects performance. In general case, reading cached data is performed faster than reading non-cached data.
String dir = "c:\\temp\\"; // Load an image from a PNG file. com.aspose.imaging.Image image = com.aspose.imaging.Image.load(dir + "sample.png"); try { // Cache all pixel data so that no additional data loading will be performed from the underlying data stream image.cacheData(); long startTime = System.currentTimeMillis(); // Reading all pixels is pretty fast. com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image; for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int color = rasterImage.getArgb32Pixel(x, y); } } long stopTime = System.currentTimeMillis(); long elapsedTime = stopTime - startTime; System.out.println("Reading all cached pixels took " + elapsedTime + " ms."); } finally { image.dispose(); } // Load an image from a PNG file image = com.aspose.imaging.Image.load(dir + "sample.png"); try { long startTime = System.currentTimeMillis(); // Reading all pixels is not as fast as when caching com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage) image; for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int color = rasterImage.getArgb32Pixel(x, y); } } long stopTime = System.currentTimeMillis(); long elapsedTime = stopTime - startTime; System.out.println("Reading all pixels without preliminary caching took " + elapsedTime + " ms."); } finally { image.dispose(); } // The output may look like this: //Reading all cached pixels took 2954 ms. // java.lang.OutOfMemoryError //at com.aspose.imaging.internal.G.be.b(Unknown Source) //at com.aspose.imaging.internal.G.be.a(Unknown Source) //at com.aspose.imaging.internal.G.be.a(Unknown Source) //at com.aspose.imaging.internal.G.be.a(Unknown Source) //at com.aspose.imaging.internal.G.aB.a(Unknown Source) //at com.aspose.imaging.RasterImage.a(Unknown Source) //at com.aspose.imaging.RasterImage.getArgb32Pixel(Unknown Source) //at com.aspose.examples.ExamplesTest.Test(ExamplesTest.java:58)
public void save()
Saves the object's data to the current DataStreamSupporter
.
public void save(OutputStream stream)
Saves the object's data to the specified stream.
stream
- The stream to save the object's data to.public void save(RandomAccessFile file)
Saves the object's data to the specified stream.
file
- The stream to save the object's data to.public void save(String filePath)
Saves the object's data to the specified file location.
filePath
- The file path to save the object's data to.public void save(String filePath, boolean overWrite)
Saves the object's data to the specified file location.
filePath
- The file path to save the object's data to.overWrite
- if set to true
over write the file contents, otherwise append will occur.