}
private int getApp14AdobeTransform(byte[] bytes)
{
int transformType = 0;
ImageReader reader = null;
ImageInputStream input = null;
try
{
input = ImageIO.createImageInputStream(new ByteArrayInputStream(bytes));
Iterator<ImageReader> readers = ImageIO.getImageReaders(input);
if (readers == null || !readers.hasNext())
{
throw new RuntimeException("No ImageReaders found");
}
reader = (ImageReader) readers.next();
reader.setInput(input);
IIOMetadata meta = reader.getImageMetadata(0);
if (meta != null)
{
Node tree = meta.getAsTree("javax_imageio_jpeg_image_1.0");
NodeList children = tree.getChildNodes();
for (int i=0;i<children.getLength();i++)
{
Node markerSequence = children.item(i);
if ("markerSequence".equals(markerSequence.getNodeName()))
{
NodeList markerSequenceChildren = markerSequence.getChildNodes();
for (int j=0;j<markerSequenceChildren.getLength();j++)
{
Node child = markerSequenceChildren.item(j);
if ("app14Adobe".equals(child.getNodeName()) && child.hasAttributes())
{
NamedNodeMap attribs = child.getAttributes();
Node transformNode = attribs.getNamedItem("transform");
transformType = Integer.parseInt(transformNode.getNodeValue());
break;
}
}
}
}
}
}
catch(IOException exception)
{
}
finally
{
try
{
if (input != null)
{
input.close();
}
}
catch (IOException exception)
{
// swallow the exception
}
if (reader != null)
{
reader.dispose();
}
}
return transformType;
}