private static final ImageParser getImageParser(ByteSource byteSource)
            throws ImageReadException, IOException {
        ImageFormat format = guessFormat(byteSource);
        if (!format.equals(ImageFormat.IMAGE_FORMAT_UNKNOWN)) {

            ImageParser imageParsers[] = ImageParser.getAllImageParsers();

            for (int i = 0; i < imageParsers.length; i++) {
                ImageParser imageParser = imageParsers[i];

                if (imageParser.canAcceptType(format))
                    return imageParser;
            }
        }

        String filename = byteSource.getFilename();
        if (filename != null) {
            ImageParser imageParsers[] = ImageParser.getAllImageParsers();

            for (int i = 0; i < imageParsers.length; i++) {
                ImageParser imageParser = imageParsers[i];

                if (imageParser.canAcceptExtension(filename))
                    return imageParser;
            }
        }

        throw new ImageReadException("Can't parse this format.");
    }