[514944] - Avoid com.sun.image.codec.jpeg.JPEGCodec and other JDK
internal API
diff --git a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/io/ImageReader.java b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/io/ImageReader.java
index 231feed..8a224e8 100644
--- a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/io/ImageReader.java
+++ b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/io/ImageReader.java
@@ -7,10 +7,15 @@
*
* Contributors:
* Junji MAEDA - initial API and implementation
+ * Kentarou FUKUDA - 514944
*******************************************************************************/
package org.eclipse.actf.visualization.internal.engines.lowvision.io;
import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
import org.eclipse.actf.visualization.engines.lowvision.LowVisionIOException;
import org.eclipse.actf.visualization.engines.lowvision.image.ImageException;
@@ -19,8 +24,7 @@
import org.eclipse.actf.visualization.internal.engines.lowvision.image.ImageUtil;
public class ImageReader {
- public static BufferedImage readBufferedImage(String _fileName)
- throws LowVisionIOException {
+ public static BufferedImage readBufferedImage(String _fileName) throws LowVisionIOException {
short type = IoUtil.getFileType(_fileName);
if (type != IoUtil.TYPE_UNKNOWN)
return (readBufferedImage(_fileName, type));
@@ -28,13 +32,17 @@
throw new LowVisionIOException("Unknown image format: _fileName"); //$NON-NLS-1$
}
- public static BufferedImage readBufferedImage(String _fileName, short _type)
- throws LowVisionIOException {
+ public static BufferedImage readBufferedImage(String _fileName, short _type) throws LowVisionIOException {
BufferedImage bufIm = null;
if (_type == IoUtil.TYPE_BMP) {
bufIm = BMPReader.readBufferedImage(_fileName);
} else if (_type == IoUtil.TYPE_JPEG) {
- bufIm = JPEGReader.readBufferedImage(_fileName);
+ try {
+ bufIm = ImageIO.read(new File(_fileName));
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new LowVisionIOException("IO error occurred while decoding JPEG file."); //$NON-NLS-1$
+ }
} else if (_type == IoUtil.TYPE_GIF) {
bufIm = ImageFileReader.readBufferedImage(_fileName);
} else if (_type == IoUtil.TYPE_PNG) {
@@ -52,29 +60,23 @@
public static IInt2D readInt2D(String _fileName) throws LowVisionIOException {
try {
- return (ImageUtil
- .bufferedImageToInt2D(readBufferedImage(_fileName)));
+ return (ImageUtil.bufferedImageToInt2D(readBufferedImage(_fileName)));
} catch (ImageException e) {
e.printStackTrace();
- throw new LowVisionIOException(
- "ImageException occurred while converting BufferedImage into Int2D."); //$NON-NLS-1$
+ throw new LowVisionIOException("ImageException occurred while converting BufferedImage into Int2D."); //$NON-NLS-1$
}
}
- public static IInt2D readInt2D(String _fileName, short _type)
- throws LowVisionIOException {
+ public static IInt2D readInt2D(String _fileName, short _type) throws LowVisionIOException {
try {
- return (ImageUtil.bufferedImageToInt2D(readBufferedImage(_fileName,
- _type)));
+ return (ImageUtil.bufferedImageToInt2D(readBufferedImage(_fileName, _type)));
} catch (ImageException e) {
e.printStackTrace();
- throw new LowVisionIOException(
- "ImageException occurred while converting BufferedImage into Int2D."); //$NON-NLS-1$
+ throw new LowVisionIOException("ImageException occurred while converting BufferedImage into Int2D."); //$NON-NLS-1$
}
}
- public static BinaryImage readBinaryImage(String _fileName)
- throws LowVisionIOException {
+ public static BinaryImage readBinaryImage(String _fileName) throws LowVisionIOException {
short type = IoUtil.getFileType(_fileName);
if (type != IoUtil.TYPE_UNKNOWN)
return (readBinaryImage(_fileName, type));
@@ -82,12 +84,22 @@
throw new LowVisionIOException("Unknown image format."); //$NON-NLS-1$
}
- public static BinaryImage readBinaryImage(String _fileName, short _type)
- throws LowVisionIOException {
+ public static BinaryImage readBinaryImage(String _fileName, short _type) throws LowVisionIOException {
if (_type == IoUtil.TYPE_PBM)
return (PBMReader.readBinaryImage(_fileName));
else
throw new LowVisionIOException("Unknown image format."); //$NON-NLS-1$
}
+ //for test
+ // public static void main(String[] args) {
+ // try {
+ // BufferedImage tmpBI = readBufferedImage("C://test/test.jpg");
+ // ImageWriter.writeBufferedImage(tmpBI, "C://test/test2.jpg");
+ // } catch (Exception e) {
+ // e.printStackTrace();
+ // }
+ //
+ // }
+
}
diff --git a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/io/ImageWriter.java b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/io/ImageWriter.java
index 61ea1cf..ad4165b 100644
--- a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/io/ImageWriter.java
+++ b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/io/ImageWriter.java
@@ -22,8 +22,7 @@
import org.eclipse.actf.visualization.internal.engines.lowvision.image.Int2D;
public class ImageWriter {
- public static void writeBufferedImage(BufferedImage _bi, String _fileName)
- throws LowVisionIOException {
+ public static void writeBufferedImage(BufferedImage _bi, String _fileName) throws LowVisionIOException {
short type = IoUtil.getFileType(_fileName);
if (type != IoUtil.TYPE_UNKNOWN)
writeBufferedImage(_bi, _fileName, type);
@@ -31,25 +30,33 @@
throw new LowVisionIOException("Unknown image format."); //$NON-NLS-1$
}
- public static void writeBufferedImage(BufferedImage _bi, String _fileName,
- short _type) throws LowVisionIOException {
+ public static void writeBufferedImage(BufferedImage _bi, String _fileName, short _type)
+ throws LowVisionIOException {
if (_type == IoUtil.TYPE_BMP)
BMPWriter.writeBufferedImage(_bi, _fileName);
- else if (_type == IoUtil.TYPE_JPEG)
- JPEGWriter.writeBufferedImage(_bi, _fileName);
- else if (_type == IoUtil.TYPE_GIF) {
+ else if (_type == IoUtil.TYPE_JPEG) {
+ boolean result = true;
+ try {
+ File targetFile = new File(_fileName);
+ result = ImageIO.write(_bi, "jpg", targetFile);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new LowVisionIOException("IO error occurred while decoding/closing."); //$NON-NLS-1$
+ }
+ if(!result){
+ throw new LowVisionIOException("No appropriate writer is found while writing a JPEG image."); //$NON-NLS-1$
+ }
+ } else if (_type == IoUtil.TYPE_GIF) {
File outFile = new File(_fileName);
boolean result = true;
try {
result = ImageIO.write(_bi, "GIF", outFile); //$NON-NLS-1$
} catch (IOException ioe) {
ioe.printStackTrace();
- throw new LowVisionIOException(
- "An error occurs while writing a GIF image."); //$NON-NLS-1$
+ throw new LowVisionIOException("An error occurs while writing a GIF image."); //$NON-NLS-1$
}
if (!result) {
- throw new LowVisionIOException(
- "No appropriate writer is found while writing a GIF image."); //$NON-NLS-1$
+ throw new LowVisionIOException("No appropriate writer is found while writing a GIF image."); //$NON-NLS-1$
}
// throw new LowVisionIOException("This file format cannot be
// written out.");
@@ -60,12 +67,10 @@
result = ImageIO.write(_bi, "PNG", outFile); //$NON-NLS-1$
} catch (IOException ioe) {
ioe.printStackTrace();
- throw new LowVisionIOException(
- "An error occurs while writing a PNG image."); //$NON-NLS-1$
+ throw new LowVisionIOException("An error occurs while writing a PNG image."); //$NON-NLS-1$
}
if (!result) {
- throw new LowVisionIOException(
- "No appropriate writer is found while writing a PNG image."); //$NON-NLS-1$
+ throw new LowVisionIOException("No appropriate writer is found while writing a PNG image."); //$NON-NLS-1$
}
// throw new LowVisionIOException("This file format cannot be
// written out.");
@@ -73,19 +78,15 @@
throw new LowVisionIOException("Unknown image format."); //$NON-NLS-1$
}
- public static void writeInt2D(Int2D _i2d, String _fileName)
- throws LowVisionIOException {
+ public static void writeInt2D(Int2D _i2d, String _fileName) throws LowVisionIOException {
writeBufferedImage(ImageUtil.int2DToBufferedImage(_i2d), _fileName);
}
- public static void writeInt2D(Int2D _i2d, String _fileName, short _type)
- throws LowVisionIOException {
- writeBufferedImage(ImageUtil.int2DToBufferedImage(_i2d), _fileName,
- _type);
+ public static void writeInt2D(Int2D _i2d, String _fileName, short _type) throws LowVisionIOException {
+ writeBufferedImage(ImageUtil.int2DToBufferedImage(_i2d), _fileName, _type);
}
- public static void writeBinaryImage(BinaryImage _bi, String _fileName)
- throws LowVisionIOException {
+ public static void writeBinaryImage(BinaryImage _bi, String _fileName) throws LowVisionIOException {
short type = IoUtil.getFileType(_fileName);
if (type != IoUtil.TYPE_UNKNOWN)
writeBinaryImage(_bi, _fileName, type);
@@ -93,8 +94,7 @@
throw new LowVisionIOException("Unknown image format."); //$NON-NLS-1$
}
- public static void writeBinaryImage(BinaryImage _bi, String _fileName,
- short _type) throws LowVisionIOException {
+ public static void writeBinaryImage(BinaryImage _bi, String _fileName, short _type) throws LowVisionIOException {
if (_type == IoUtil.TYPE_PBM)
PBMWriter.writeBinaryImage(_bi, _fileName);
else
diff --git a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/io/JPEGReader.java b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/io/JPEGReader.java
deleted file mode 100644
index c396ef9..0000000
--- a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/io/JPEGReader.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2008 IBM Corporation and Others
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Junji MAEDA - initial API and implementation
- *******************************************************************************/
-package org.eclipse.actf.visualization.internal.engines.lowvision.io;
-
-import java.awt.image.BufferedImage;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-
-import org.eclipse.actf.visualization.engines.lowvision.LowVisionIOException;
-
-import com.sun.image.codec.jpeg.JPEGCodec;
-import com.sun.image.codec.jpeg.JPEGImageDecoder;
-
-public class JPEGReader {
- public static BufferedImage readBufferedImage(String _fileName)
- throws LowVisionIOException {
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(_fileName);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- throw new LowVisionIOException("The file was not found: " //$NON-NLS-1$
- + _fileName);
- }
-
- JPEGImageDecoder dec = null;
- try {
- dec = JPEGCodec.createJPEGDecoder(fis);
- BufferedImage bi = dec.decodeAsBufferedImage();
- fis.close();
- return (bi);
- } catch (IOException e) {
- e.printStackTrace();
- throw new LowVisionIOException(
- "IO error occurred while decoding JPEG file."); //$NON-NLS-1$
- }
- }
-}
diff --git a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/io/JPEGWriter.java b/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/io/JPEGWriter.java
deleted file mode 100644
index c73bfed..0000000
--- a/plugins/org.eclipse.actf.visualization.engines.lowvision/src/org/eclipse/actf/visualization/internal/engines/lowvision/io/JPEGWriter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2008 IBM Corporation and Others
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Junji MAEDA - initial API and implementation
- *******************************************************************************/
-package org.eclipse.actf.visualization.internal.engines.lowvision.io;
-
-import java.awt.image.BufferedImage;
-import java.io.BufferedOutputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-import org.eclipse.actf.visualization.engines.lowvision.LowVisionIOException;
-
-import com.sun.image.codec.jpeg.JPEGCodec;
-import com.sun.image.codec.jpeg.JPEGImageEncoder;
-
-public class JPEGWriter {
- public static void writeBufferedImage(BufferedImage _bi, String _fileName)
- throws LowVisionIOException {
- BufferedOutputStream bos = null;
- try {
- bos = new BufferedOutputStream(new FileOutputStream(_fileName));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- throw new LowVisionIOException("The file was not found: " //$NON-NLS-1$
- + _fileName);
- }
-
- try {
- JPEGImageEncoder enc = JPEGCodec.createJPEGEncoder(bos);
- enc.encode(_bi);
- bos.close();
- } catch (IOException e) {
- e.printStackTrace();
- throw new LowVisionIOException(
- "IO error occurred while decoding/closing."); //$NON-NLS-1$
- }
- }
-}