use of javax.imageio.stream.MemoryCacheImageInputStream in project openolat by klemens.
the class ImageUtils method getImageSize.
public static Size getImageSize(String suffix, InputStream in) {
Size result = null;
Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
if (iter.hasNext()) {
ImageReader reader = iter.next();
try {
ImageInputStream stream = new MemoryCacheImageInputStream(in);
reader.setInput(stream);
int imageIndex = reader.getMinIndex();
int width = reader.getWidth(imageIndex);
int height = reader.getHeight(imageIndex);
result = new Size(width, height, 0, 0, false);
} catch (IOException e) {
log.error(e.getMessage());
} finally {
IOUtils.closeQuietly(in);
reader.dispose();
}
} else {
log.error("No reader found for given format: " + suffix);
}
return result;
}
use of javax.imageio.stream.MemoryCacheImageInputStream in project openolat by klemens.
the class AbstractImageHelper method getImageSize.
private Size getImageSize(VFSLeaf media, String suffix) {
Size result = null;
Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
if (iter.hasNext()) {
ImageInputStream stream = null;
InputStream mediaStream = null;
ImageReader reader = iter.next();
try {
mediaStream = media.getInputStream();
if (mediaStream != null) {
stream = new MemoryCacheImageInputStream(mediaStream);
reader.setInput(stream);
int readerMinIndex = reader.getMinIndex();
int width = reader.getWidth(readerMinIndex);
int height = reader.getHeight(readerMinIndex);
result = new Size(width, height, 0, 0, false);
}
} catch (IOException e) {
log.error(e.getMessage());
} finally {
IOUtils.closeQuietly(stream);
IOUtils.closeQuietly(mediaStream);
reader.dispose();
}
} else {
log.error("No reader found for given format: " + suffix);
}
return result;
}
use of javax.imageio.stream.MemoryCacheImageInputStream in project openolat by klemens.
the class AbstractImageHelper method getImageSize.
private Size getImageSize(File media, String suffix) {
Size result = null;
Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
if (iter.hasNext()) {
ImageReader reader = iter.next();
try (InputStream mediaStream = new FileInputStream(media);
ImageInputStream stream = new MemoryCacheImageInputStream(mediaStream)) {
reader.setInput(stream);
int readerMinIndex = reader.getMinIndex();
int width = reader.getWidth(readerMinIndex);
int height = reader.getHeight(readerMinIndex);
result = new Size(width, height, 0, 0, false);
} catch (IOException e) {
log.error(e.getMessage());
} finally {
reader.dispose();
}
} else {
log.error("No reader found for given format: " + suffix);
}
return result;
}
use of javax.imageio.stream.MemoryCacheImageInputStream in project wcomponents by BorderTech.
the class ThumbnailUtil method createImageThumbnail.
/**
* This method will create a JPEG "thumb nail" of an image read from an {@link InputStream}. The maximum Dimension
* of the returned JPEG Image will be {@link #THUMBNAIL_MAX}.
*
* @param is the InputStream representing the image for which the JPEG thumb nail is to be returned.
* @param scaledSize the size to which the given <em>image</em> is to be scaled.
* @return a byte[] representing the JPEG thumb nail.
*/
private static byte[] createImageThumbnail(final InputStream is, final Dimension scaledSize) {
BufferedImage image;
MemoryCacheImageInputStream mciis;
try {
mciis = new MemoryCacheImageInputStream(is);
image = ImageIO.read(mciis);
} catch (Exception e) {
LOG.warn("Unable to read input image", e);
return null;
}
if (image == null) {
return null;
}
try {
byte[] jpeg = createScaledJPEG(image, scaledSize);
return jpeg;
} catch (Exception e) {
LOG.error("Error creating thumbnail from image", e);
} finally {
image.flush();
}
return null;
}
use of javax.imageio.stream.MemoryCacheImageInputStream in project openj9 by eclipse.
the class UnwindTable method dumpInstructions.
/*
* Dump the instructions, basically a copy of processInstruction with just the print
* statements left in.
* Some instructions create rules, others adjust the address the instructions
* apply to and others save/restore state to a stack.
* See: DWARF Debugging Information Format, Version 3 section 6.4.2
* (Also extra instructions defined for Exception handling in:
* http://refspecs.linux-foundation.org/LSB_4.0.0/LSB-Core-generic/LSB-Core-generic/dwarfext.html
* )
*/
public static void dumpInstructions(PrintStream out, byte[] instructions, CIE cie) throws IOException {
try {
InputStream i = new ByteArrayInputStream(instructions);
ImageInputStream instructionStream = new MemoryCacheImageInputStream(i);
instructionStream.setByteOrder(cie.byteOrder);
while (instructionStream.getStreamPosition() < instructions.length) {
dumpInstruction(out, instructionStream, cie);
out.println();
}
} catch (Exception e) {
out.println("Error dumping instructions: " + e);
e.printStackTrace(out);
}
}
Aggregations