/** * Read the specified input stream using the specified loader, and * return the device independent image array represented by the stream. */ public static ImageData[] load(InputStream is, ImageLoader loader) { FileFormat fileFormat = null; LEDataInputStream stream = new LEDataInputStream(is); for (int i = 1; i < FORMATS.length; i++) { if (FORMATS[i] != null) { try { fileFormat = getFileFormat (stream, FORMATS[i]); if (fileFormat != null) break; } catch (ClassNotFoundException e) { FORMATS[i] = null; } catch (Exception e) { } } } if (fileFormat == null) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); fileFormat.loader = loader; return fileFormat.loadFromStream(stream); }
static FileFormat getFileFormat (LEDataInputStream stream, String format) throws Exception { Class<?> clazz = Class.forName(FORMAT_PACKAGE + '.' + format + FORMAT_SUFFIX); FileFormat fileFormat = (FileFormat) clazz.newInstance(); if (fileFormat.isFileFormat(stream)) return fileFormat; return null; }
FileFormat.save(stream, format, this);
/** * Write the device independent image array stored in the specified loader * to the specified output stream. */ public void unloadIntoStream(ImageLoader loader, LEDataOutputStream stream) { try { outputStream = stream; unloadIntoByteStream(loader); outputStream.flush(); } catch (Exception e) { try {outputStream.flush();} catch (Exception f) {} SWT.error(SWT.ERROR_IO, e); } } }
/** * Read the specified input stream, and return the * device independent image array represented by the stream. */ public ImageData[] loadFromStream(LEDataInputStream stream) { try { inputStream = stream; return loadFromByteStream(); } catch (Exception e) { if (e instanceof IOException) { SWT.error(SWT.ERROR_IO, e); } else { SWT.error(SWT.ERROR_INVALID_IMAGE, e); } return null; } }
/** * Write the device independent image array stored in the specified loader * to the specified output stream using the specified file format. */ public static void save(OutputStream os, int format, ImageLoader loader) { if (format < 0 || format >= FORMATS.length) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); if (FORMATS[format] == null) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); if (loader.data == null || loader.data.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); LEDataOutputStream stream = new LEDataOutputStream(os); FileFormat fileFormat = null; try { Class clazz = Class.forName(FORMAT_PACKAGE + '.' + FORMATS[format] + FORMAT_SUFFIX); fileFormat = (FileFormat) clazz.newInstance(); } catch (Exception e) { SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); } if (format == SWT.IMAGE_BMP_RLE) { switch (loader.data[0].depth) { case 8: fileFormat.compression = 1; break; case 4: fileFormat.compression = 2; break; } } fileFormat.unloadIntoStream(loader, stream); }
/** * Loads an array of <code>ImageData</code> objects from the * specified input stream. Throws an error if either an error * occurs while loading the images, or if the images are not * of a supported type. Returns the loaded image data array. * * @param stream the input stream to load the images from * @return an array of <code>ImageData</code> objects loaded from the specified input stream * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the stream is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_IO - if an IO error occurs while reading from the stream</li> * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data</li> * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li> * </ul> */ public ImageData[] load(InputStream stream) { if (stream == null) { SWT.error(SWT.ERROR_NULL_ARGUMENT); } reset(); data = FileFormat.load(stream, this); return data; }
if (png != null) { png.loader = this.loader; return png.loadFromStream(inputStream)[0];
/** * Write the device independent image array stored in the specified loader * to the specified output stream. */ public void unloadIntoStream(ImageLoader loader, LEDataOutputStream stream) { try { outputStream = stream; unloadIntoByteStream(loader); outputStream.flush(); } catch (Exception e) { try {outputStream.flush();} catch (Exception f) {} SWT.error(SWT.ERROR_IO, e); } } }
/** * Read the specified input stream, and return the * device independent image array represented by the stream. */ public ImageData[] loadFromStream(LEDataInputStream stream) { try { inputStream = stream; return loadFromByteStream(); } catch (Exception e) { if (e instanceof IOException) { SWT.error(SWT.ERROR_IO, e); } else { SWT.error(SWT.ERROR_INVALID_IMAGE, e); } return null; } }
/** * Write the device independent image array stored in the specified loader * to the specified output stream using the specified file format. */ public static void save(OutputStream os, int format, ImageLoader loader) { if (format < 0 || format >= FORMATS.length) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); if (FORMATS[format] == null) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); if (loader.data == null || loader.data.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); LEDataOutputStream stream = new LEDataOutputStream(os); FileFormat fileFormat = null; try { Class<?> clazz = Class.forName(FORMAT_PACKAGE + '.' + FORMATS[format] + FORMAT_SUFFIX); fileFormat = (FileFormat) clazz.newInstance(); } catch (Exception e) { SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); } if (format == SWT.IMAGE_BMP_RLE) { switch (loader.data[0].depth) { case 8: fileFormat.compression = 1; break; case 4: fileFormat.compression = 2; break; } } fileFormat.unloadIntoStream(loader, stream); }
/** * Loads an array of <code>ImageData</code> objects from the * specified input stream. Throws an error if either an error * occurs while loading the images, or if the images are not * of a supported type. Returns the loaded image data array. * * @param stream the input stream to load the images from * @return an array of <code>ImageData</code> objects loaded from the specified input stream * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the stream is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_IO - if an IO error occurs while reading from the stream</li> * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data</li> * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li> * </ul> */ public ImageData[] load(InputStream stream) { if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); reset(); data = FileFormat.load(stream, this); return data; }
if (png != null) { png.loader = this.loader; return png.loadFromStream(inputStream)[0];
/** * Read the specified input stream using the specified loader, and * return the device independent image array represented by the stream. */ public static ImageData[] load(InputStream is, ImageLoader loader) { FileFormat fileFormat = null; LEDataInputStream stream = new LEDataInputStream(is); for (int i = 1; i < FORMATS.length; i++) { if (FORMATS[i] != null) { try { fileFormat = getFileFormat (stream, FORMATS[i]); if (fileFormat != null) break; } catch (ClassNotFoundException e) { FORMATS[i] = null; } catch (Exception e) { } } } if (fileFormat == null) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); fileFormat.loader = loader; return fileFormat.loadFromStream(stream); }
static FileFormat getFileFormat (LEDataInputStream stream, String format) throws Exception { Class<?> clazz = Class.forName(FORMAT_PACKAGE + '.' + format + FORMAT_SUFFIX); FileFormat fileFormat = (FileFormat) clazz.newInstance(); if (fileFormat.isFileFormat(stream)) return fileFormat; return null; }
/** * Write the device independent image array stored in the specified loader * to the specified output stream. */ public void unloadIntoStream(ImageLoader loader, LEDataOutputStream stream) { try { outputStream = stream; unloadIntoByteStream(loader); outputStream.flush(); } catch (Exception e) { try {outputStream.flush();} catch (Exception f) {} SWT.error(SWT.ERROR_IO, e); } } }
/** * Read the specified input stream, and return the * device independent image array represented by the stream. */ public ImageData[] loadFromStream(LEDataInputStream stream) { try { inputStream = stream; return loadFromByteStream(); } catch (Exception e) { if (e instanceof IOException) { SWT.error(SWT.ERROR_IO, e); } else { SWT.error(SWT.ERROR_INVALID_IMAGE, e); } return null; } }
/** * Write the device independent image array stored in the specified loader * to the specified output stream using the specified file format. */ public static void save(OutputStream os, int format, ImageLoader loader) { if (format < 0 || format >= FORMATS.length) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); if (FORMATS[format] == null) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); if (loader.data == null || loader.data.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); LEDataOutputStream stream = new LEDataOutputStream(os); FileFormat fileFormat = null; try { Class<?> clazz = Class.forName(FORMAT_PACKAGE + '.' + FORMATS[format] + FORMAT_SUFFIX); fileFormat = (FileFormat) clazz.newInstance(); } catch (Exception e) { SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); } if (format == SWT.IMAGE_BMP_RLE) { switch (loader.data[0].depth) { case 8: fileFormat.compression = 1; break; case 4: fileFormat.compression = 2; break; } } fileFormat.unloadIntoStream(loader, stream); }
/** * Loads an array of <code>ImageData</code> objects from the * specified input stream. Throws an error if either an error * occurs while loading the images, or if the images are not * of a supported type. Returns the loaded image data array. * * @param stream the input stream to load the images from * @return an array of <code>ImageData</code> objects loaded from the specified input stream * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the stream is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_IO - if an IO error occurs while reading from the stream</li> * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data</li> * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li> * </ul> */ public ImageData[] load(InputStream stream) { if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); reset(); data = FileFormat.load(stream, this); return data; }
FileFormat.save(stream, format, this);