Search in sources :

Example 31 with FileImageInputStream

use of javax.imageio.stream.FileImageInputStream in project openj9 by eclipse.

the class ELFFileReader method getELFFileReaderWithOffset.

// ELF files can be either Big Endian (for example on Linux/PPC) or Little
// Endian (Linux/IA).
// Let's check whether it's actually an ELF file. We'll sort out the byte
// order later.
public static ELFFileReader getELFFileReaderWithOffset(File f, long offset) throws IOException, InvalidDumpFormatException {
    // Figure out which combination of bitness and architecture we are
    ImageInputStream in = new FileImageInputStream(f);
    if (!isFormatValid(in)) {
        throw new InvalidDumpFormatException("File " + f.getAbsolutePath() + " is not an ELF file");
    }
    int bitness = in.read();
    ByteOrder byteOrder = getByteOrder(in);
    // no longer need the input stream as passing the File descriptor into the reader
    in.close();
    if (ELFCLASS64 == bitness) {
        return new ELF64FileReader(f, byteOrder, offset);
    } else {
        return new ELF32FileReader(f, byteOrder, offset);
    }
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) InvalidDumpFormatException(com.ibm.j9ddr.corereaders.InvalidDumpFormatException) ByteOrder(java.nio.ByteOrder)

Example 32 with FileImageInputStream

use of javax.imageio.stream.FileImageInputStream in project openj9 by eclipse.

the class PrintBlob method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("Expected 1 argument. Got " + args.length);
        System.exit(1);
    }
    File blobFile = new File(args[0]);
    ImageInputStream iis = new FileImageInputStream(blobFile);
    iis.setByteOrder(ByteOrder.LITTLE_ENDIAN);
    StructureReader structReader = new StructureReader(iis);
    List<StructureDescriptor> structures = new ArrayList<StructureDescriptor>(structReader.getStructures());
    Collections.sort(structures, new Comparator<StructureDescriptor>() {

        public int compare(StructureDescriptor o1, StructureDescriptor o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    for (StructureDescriptor thisStruct : structures) {
        String superClass = thisStruct.getSuperName();
        if (superClass != null && superClass.length() > 0) {
            System.out.println("Structure: " + thisStruct.getName() + " extends " + superClass);
        } else {
            System.out.println("Structure: " + thisStruct.getName());
        }
    // List<FieldDescriptor> fields = new ArrayList<FieldDescriptor>(thisStruct.getFields());
    // 
    // Collections.sort(fields, new Comparator<FieldDescriptor>(){
    // 
    // public int compare(FieldDescriptor o1, FieldDescriptor o2)
    // {
    // return o1.getName().compareTo(o2.getName());
    // }});
    // 
    // System.out.println("\tFields");
    // 
    // for (FieldDescriptor thisField : fields) {
    // System.out.println("\t\t" + thisField.getName() + " - " + thisField.getType());
    // }
    // 
    // List<ConstantDescriptor> constants = new ArrayList<ConstantDescriptor>(thisStruct.getConstants());
    // 
    // Collections.sort(constants, new Comparator<ConstantDescriptor>(){
    // 
    // public int compare(ConstantDescriptor o1, ConstantDescriptor o2)
    // {
    // return o1.getName().compareTo(o2.getName());
    // }});
    // 
    // System.out.println("\tConstants:");
    // for (ConstantDescriptor thisConstant : constants) {
    // System.out.println("\t\t" + thisConstant.getName());
    // }
    }
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) StructureReader(com.ibm.j9ddr.StructureReader) ArrayList(java.util.ArrayList) File(java.io.File) StructureDescriptor(com.ibm.j9ddr.StructureReader.StructureDescriptor)

Example 33 with FileImageInputStream

use of javax.imageio.stream.FileImageInputStream in project digilib by robcast.

the class JAIImageLoaderDocuImage method getReader.

/* Get an ImageReader for the image file. */
public ImageReader getReader(ImageInput input) throws IOException {
    logger.debug("get ImageReader for " + input);
    if (this.reader != null) {
        if (this.input == input) {
            // it was the same input
            logger.debug("reusing Reader");
            return reader;
        }
        // clean up old reader
        logger.debug("cleaning Reader!");
        dispose();
    }
    this.input = input;
    ImageInputStream istream = null;
    if (input.hasImageInputStream()) {
        // stream input
        istream = input.getImageInputStream();
    } else if (input.hasFile()) {
        // file only input
        RandomAccessFile rf = new RandomAccessFile(input.getFile(), "r");
        istream = new FileImageInputStream(rf);
    } else {
        throw new FileOpException("Unable to get data from ImageInput");
    }
    Iterator<ImageReader> readers;
    String mt = input.getMimetype();
    if (mt == null) {
        logger.debug("No mime-type. Trying automagic.");
        readers = ImageIO.getImageReaders(istream);
    } else {
        logger.debug("File type:" + mt);
        readers = ImageIO.getImageReadersByMIMEType(mt);
    }
    if (!readers.hasNext()) {
        throw new FileOpException("Can't find Reader to load File!");
    }
    reader = readers.next();
    logger.debug("ImageIO: this reader: " + reader.getClass());
    /* are there more readers? */
    /* while (readers.hasNext()) {
            logger.debug("ImageIO: next reader: " + readers.next().getClass());
        } */
    reader.setInput(istream);
    return reader;
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) RandomAccessFile(java.io.RandomAccessFile) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) FileOpException(digilib.io.FileOpException) ImageReader(javax.imageio.ImageReader)

Example 34 with FileImageInputStream

use of javax.imageio.stream.FileImageInputStream in project digilib by robcast.

the class ImageLoaderDocuImage method getReader.

/**
 * Get an ImageReader for the image file.
 *
 * @return
 */
public ImageReader getReader(ImageInput input) throws IOException {
    logger.debug("get ImageReader for " + input);
    if (reuseReader && reader != null) {
        logger.debug("reuseing ImageReader");
        return reader;
    }
    ImageInputStream istream = null;
    if (input.hasImageInputStream()) {
        // ImageInputStream input
        istream = input.getImageInputStream();
    } else if (input.hasFile()) {
        // file only input
        RandomAccessFile rf = new RandomAccessFile(input.getFile(), "r");
        istream = new FileImageInputStream(rf);
    } else {
        throw new FileOpException("Unable to get data from ImageInput");
    }
    Iterator<ImageReader> readers;
    String mt = null;
    if (input.hasMimetype()) {
        // check hasMimetype first or we might get into a loop
        mt = input.getMimetype();
    } else {
        // try file extension
        mt = FileOps.mimeForFile(input.getFile());
    }
    if (mt == null) {
        logger.debug("No mime-type. Trying automagic.");
        readers = ImageIO.getImageReaders(istream);
    } else {
        logger.debug("File type:" + mt);
        readers = ImageIO.getImageReadersByMIMEType(mt);
    }
    if (!readers.hasNext()) {
        throw new FileOpException("Can't find Reader to load File!");
    }
    ImageReader reader = readers.next();
    if (reader == null) {
        throw new FileOpException("Error getting Reader to load File!");
    }
    logger.debug("ImageIO: this reader: " + reader.getClass());
    /*
        while (readers.hasNext()) { 
        	logger.debug("ImageIO: next reader: " + readers.next().getClass()); 
        }
        */
    reader.setInput(istream);
    return reader;
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) RandomAccessFile(java.io.RandomAccessFile) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) FileOpException(digilib.io.FileOpException) ImageReader(javax.imageio.ImageReader)

Example 35 with FileImageInputStream

use of javax.imageio.stream.FileImageInputStream in project openolat by klemens.

the class ImageHelperImpl method scaleImage.

/**
 * @param image The image to scale
 * @param imageExt The extension if not given by the image file (optional)
 * @param scaledImaged the new scaled image
 * @param maxWidth the maximum width of the new scaled image
 * @param maxheight the maximum height of the new scaled image
 * @return
 */
@Override
public Size scaleImage(File image, String imageExt, File scaledImage, int maxWidth, int maxHeight, boolean fill) {
    ImageInputStream imageSrc = null;
    try {
        imageSrc = new FileImageInputStream(image);
        SizeAndBufferedImage scaledSize = calcScaledSize(imageSrc, imageExt, maxWidth, maxHeight, fill);
        if (scaledSize == null || scaledSize.image == null) {
            return null;
        }
        if (!scaledSize.getScaledSize().isChanged() && isSameFormat(image, imageExt, scaledImage)) {
            if (FileUtils.copyFileToFile(image, scaledImage, false)) {
                return scaledSize.getSize();
            }
        }
        BufferedImage bufferedImage = scaledSize.image;
        BufferedImage scaledBufferedImage = scaleTo(bufferedImage, scaledSize.getScaledSize());
        if (writeTo(scaledBufferedImage, scaledImage, scaledSize.getScaledSize(), getImageFormat(scaledImage))) {
            return scaledSize.getScaledSize();
        }
        return null;
    } catch (IOException e) {
        return null;
    // fxdiff FXOLAT-109: prevent red screen if the image has wrong EXIF data
    } catch (CMMException e) {
        return null;
    } finally {
        closeQuietly(imageSrc);
    }
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) IOException(java.io.IOException) CMMException(java.awt.color.CMMException) BufferedImage(java.awt.image.BufferedImage)

Aggregations

FileImageInputStream (javax.imageio.stream.FileImageInputStream)36 File (java.io.File)22 BufferedImage (java.awt.image.BufferedImage)19 IOException (java.io.IOException)16 ImageInputStream (javax.imageio.stream.ImageInputStream)15 ImageReader (javax.imageio.ImageReader)14 Test (org.junit.Test)14 MemoryCacheImageInputStream (javax.imageio.stream.MemoryCacheImageInputStream)10 TIFFImageReaderSpi (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi)9 TIFFImageReader (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader)7 RenderedImage (java.awt.image.RenderedImage)7 ImageReadParam (javax.imageio.ImageReadParam)7 Rectangle (java.awt.Rectangle)6 FileImageOutputStream (javax.imageio.stream.FileImageOutputStream)4 CMMException (java.awt.color.CMMException)3 InputStream (java.io.InputStream)3 RandomAccessFile (java.io.RandomAccessFile)3 IIOImage (javax.imageio.IIOImage)3 ImageOutputStream (javax.imageio.stream.ImageOutputStream)3 JPEGImageReaderSpi (com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi)2