You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ml...@apache.org on 2006/11/23 09:29:17 UTC
svn commit: r478511 - in
/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java:
javax/imageio/ javax/imageio/plugins/bmp/ javax/imageio/spi/
javax/imageio/stream/ org/apache/harmony/x/imageio/plugins/jpeg/
org/apache/harmony/x/imageio/plugins/...
Author: mloenko
Date: Thu Nov 23 00:29:16 2006
New Revision: 478511
URL: http://svn.apache.org/viewvc?view=rev&rev=478511
Log:
applied patch for HARMONY-2215
[classlib][imageio] Missing API in imageio.stream package, new spi's, bmp write param, png reader and more
Added:
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/plugins/bmp/
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/plugins/bmp/BMPImageWriteParam.java (with props)
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileCacheImageInputStream.java (with props)
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileCacheImageOutputStream.java (with props)
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileImageInputStream.java (with props)
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/MemoryCacheImageInputStream.java (with props)
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/MemoryCacheImageOutputStream.java (with props)
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReader.java (with props)
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReaderSpi.java (with props)
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/InputStreamIISSpi.java (with props)
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/OutputStreamIOSSpi.java (with props)
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/stream/
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/stream/RandomAccessMemoryCache.java (with props)
Modified:
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/IIOParam.java
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageIO.java
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGSpiConsts.java
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/FileIISSpi.java
harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/RAFIISSpi.java
Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/IIOParam.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/IIOParam.java?view=diff&rev=478511&r1=478510&r2=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/IIOParam.java (original)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/IIOParam.java Thu Nov 23 00:29:16 2006
@@ -24,13 +24,13 @@
public abstract class IIOParam {
protected Rectangle sourceRegion;
- protected int sourceXSubsampling;
- protected int sourceYSubsampling;
+ protected int sourceXSubsampling = 1;
+ protected int sourceYSubsampling = 1;
protected int subsamplingXOffset;
protected int subsamplingYOffset;
protected int[] sourceBands;
protected ImageTypeSpecifier destinationType;
- protected Point destinationOffset;
+ protected Point destinationOffset = new Point(0, 0);
protected IIOParamController defaultController;
protected IIOParamController controller;
@@ -66,6 +66,9 @@
}
public Rectangle getSourceRegion() {
+ if (sourceRegion == null) {
+ return null;
+ }
//-- clone it to avoid unexpected modifications
return (Rectangle) sourceRegion.clone();
}
@@ -141,13 +144,15 @@
}
public void setDestinationOffset(Point destinationOffset) {
- // TODO implement
- throw new UnsupportedOperationException("not implemented yet");
+ if (destinationOffset == null) {
+ throw new IllegalArgumentException("destinationOffset == null!");
+ }
+
+ this.destinationOffset = (Point) destinationOffset.clone();
}
public Point getDestinationOffset() {
- // TODO implement
- throw new UnsupportedOperationException("not implemented yet");
+ return (Point) destinationOffset.clone();
}
public void setController(IIOParamController controller) {
Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageIO.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageIO.java?view=diff&rev=478511&r1=478510&r2=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageIO.java (original)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/ImageIO.java Thu Nov 23 00:29:16 2006
@@ -92,6 +92,7 @@
while (it.hasNext()) {
ImageOutputStreamSpi spi = it.next();
if (spi.getOutputClass().isInstance(output)) {
+ // todo - use getUseCache and getCacheDir here
return spi.createOutputStreamInstance(output);
}
}
@@ -203,24 +204,58 @@
throw new UnsupportedOperationException("Not supported yet");
}
- public static BufferedImage read(File input)
- throws IOException {
- throw new UnsupportedOperationException("Not supported yet");
+ public static BufferedImage read(File input) throws IOException {
+ if (input == null) {
+ throw new IllegalArgumentException("input == null!");
+ }
+
+ ImageInputStream stream = createImageInputStream(input);
+ return read(stream);
}
- public static BufferedImage read(InputStream input)
- throws IOException {
- throw new UnsupportedOperationException("Not supported yet");
+ public static BufferedImage read(InputStream input) throws IOException {
+ if (input == null) {
+ throw new IllegalArgumentException("input == null!");
+ }
+
+ ImageInputStream stream = createImageInputStream(input);
+ return read(stream);
}
- public static BufferedImage read(URL input)
- throws IOException {
- throw new UnsupportedOperationException("Not supported yet");
+ public static BufferedImage read(URL input) throws IOException {
+ if (input == null) {
+ throw new IllegalArgumentException("input == null!");
+ }
+
+ InputStream stream = input.openStream();
+ BufferedImage res = read(stream);
+ stream.close();
+
+ return res;
}
- public static BufferedImage read(ImageInputStream stream)
- throws IOException {
- throw new UnsupportedOperationException("Not supported yet");
+ public static BufferedImage read(ImageInputStream stream) throws IOException {
+ if (stream == null) {
+ throw new IllegalArgumentException("stream == null!");
+ }
+
+ Iterator<ImageReader> imageReaders = getImageReaders(stream);
+ if (!imageReaders.hasNext()) {
+ return null;
+ }
+
+ ImageReader reader = imageReaders.next();
+ reader.setInput(stream, false, true);
+ BufferedImage res = reader.read(0);
+ reader.dispose();
+
+ try {
+ stream.close();
+ } catch (IOException e) {
+ // Stream could be already closed, proceed silently in this case
+ }
+
+ return res;
}
public static boolean write(RenderedImage im,
Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/plugins/bmp/BMPImageWriteParam.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/plugins/bmp/BMPImageWriteParam.java?view=auto&rev=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/plugins/bmp/BMPImageWriteParam.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/plugins/bmp/BMPImageWriteParam.java Thu Nov 23 00:29:16 2006
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package javax.imageio.plugins.bmp;
+
+import javax.imageio.ImageWriteParam;
+import java.util.Locale;
+
+public class BMPImageWriteParam extends ImageWriteParam {
+ private boolean topDown; // Default is bottom-up
+
+ public BMPImageWriteParam() {
+ this(null);
+ }
+
+ public BMPImageWriteParam(Locale locale) {
+ super(locale);
+
+ // Set the compression
+ canWriteCompressed = true;
+ compressionTypes = new String[] {"BI_RGB", "BI_RLE8", "BI_RLE4", "BI_BITFIELDS"};
+ compressionType = compressionTypes[0];
+ }
+
+ public void setTopDown(boolean topDown) {
+ this.topDown = topDown;
+ }
+
+ public boolean isTopDown() {
+ return topDown;
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/plugins/bmp/BMPImageWriteParam.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java?view=diff&rev=478511&r1=478510&r2=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java (original)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/spi/IIORegistry.java Thu Nov 23 00:29:16 2006
@@ -23,8 +23,11 @@
import java.util.Arrays;
import org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageReaderSpi;
import org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageWriterSpi;
+import org.apache.harmony.x.imageio.plugins.png.PNGImageReaderSpi;
import org.apache.harmony.x.imageio.spi.FileIISSpi;
import org.apache.harmony.x.imageio.spi.FileIOSSpi;
+import org.apache.harmony.x.imageio.spi.InputStreamIISSpi;
+import org.apache.harmony.x.imageio.spi.OutputStreamIOSSpi;
import org.apache.harmony.x.imageio.spi.RAFIISSpi;
import org.apache.harmony.x.imageio.spi.RAFIOSSpi;
@@ -53,10 +56,13 @@
private void registerBuiltinSpis() {
registerServiceProvider(new JPEGImageWriterSpi());
registerServiceProvider(new JPEGImageReaderSpi());
+ registerServiceProvider(new PNGImageReaderSpi());
registerServiceProvider(new FileIOSSpi());
registerServiceProvider(new FileIISSpi());
registerServiceProvider(new RAFIOSSpi());
registerServiceProvider(new RAFIISSpi());
+ registerServiceProvider(new OutputStreamIOSSpi());
+ registerServiceProvider(new InputStreamIISSpi());
//-- TODO implement
}
Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileCacheImageInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileCacheImageInputStream.java?view=auto&rev=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileCacheImageInputStream.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileCacheImageInputStream.java Thu Nov 23 00:29:16 2006
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package javax.imageio.stream;
+
+import java.io.*;
+
+public class FileCacheImageInputStream extends ImageInputStreamImpl {
+ private InputStream is;
+ private File file;
+ private RandomAccessFile raf;
+
+
+ public FileCacheImageInputStream(InputStream stream, File cacheDir) throws IOException {
+ if (stream == null) {
+ throw new IllegalArgumentException("stream == null!");
+ }
+ is = stream;
+
+ if (cacheDir == null || cacheDir.isDirectory()) {
+ file = File.createTempFile(FileCacheImageOutputStream.IIO_TEMP_FILE_PREFIX, null, cacheDir);
+ file.deleteOnExit();
+ } else {
+ throw new IllegalArgumentException("Not a directory!");
+ }
+
+ raf = new RandomAccessFile(file, "rw");
+ }
+
+ @Override
+ public int read() throws IOException {
+ bitOffset = 0;
+
+ if (streamPos >= raf.length()) {
+ int b = is.read();
+
+ if (b < 0) {
+ return -1;
+ }
+
+ raf.seek(streamPos++);
+ raf.write(b);
+ return b;
+ }
+
+ raf.seek(streamPos++);
+ return raf.read();
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ bitOffset = 0;
+
+ if (streamPos >= raf.length()) {
+ int nBytes = is.read(b, off, len);
+
+ if (nBytes < 0) {
+ return -1;
+ }
+
+ raf.seek(streamPos);
+ raf.write(b, off, nBytes);
+ streamPos += nBytes;
+ return nBytes;
+ }
+
+ raf.seek(streamPos);
+ int nBytes = raf.read(b, off, len);
+ streamPos += nBytes;
+ return nBytes;
+ }
+
+ @Override
+ public boolean isCached() {
+ return true;
+ }
+
+ @Override
+ public boolean isCachedFile() {
+ return true;
+ }
+
+ @Override
+ public boolean isCachedMemory() {
+ return false;
+ }
+
+ @Override
+ public void close() throws IOException {
+ super.close();
+ raf.close();
+ file.delete();
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileCacheImageInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileCacheImageOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileCacheImageOutputStream.java?view=auto&rev=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileCacheImageOutputStream.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileCacheImageOutputStream.java Thu Nov 23 00:29:16 2006
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package javax.imageio.stream;
+
+import java.io.IOException;
+import java.io.File;
+import java.io.OutputStream;
+import java.io.RandomAccessFile;
+
+public class FileCacheImageOutputStream extends ImageOutputStreamImpl {
+ static final String IIO_TEMP_FILE_PREFIX = "iioCache";
+ static final int MAX_BUFFER_LEN = 1048575; // 1 MB - is it not too much?
+
+ private OutputStream os;
+ private File file;
+ private RandomAccessFile raf;
+
+ public FileCacheImageOutputStream(OutputStream stream, File cacheDir) throws IOException {
+ if (stream == null) {
+ throw new IllegalArgumentException("stream == null!");
+ }
+ os = stream;
+
+ if (cacheDir == null || cacheDir.isDirectory()) {
+ file = File.createTempFile(IIO_TEMP_FILE_PREFIX, null, cacheDir);
+ file.deleteOnExit();
+ } else {
+ throw new IllegalArgumentException("Not a directory!");
+ }
+
+ raf = new RandomAccessFile(file, "rw");
+ }
+
+ @Override
+ public void close() throws IOException {
+ flushBefore(raf.length());
+ super.close();
+ raf.close();
+ file.delete();
+ }
+
+ @Override
+ public boolean isCached() {
+ return true;
+ }
+
+ @Override
+ public boolean isCachedFile() {
+ return true;
+ }
+
+ @Override
+ public boolean isCachedMemory() {
+ return false;
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ flushBits(); // See the flushBits method description
+
+ raf.write(b);
+ streamPos++;
+ }
+
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException {
+ flushBits(); // See the flushBits method description
+
+ raf.write(b, off, len);
+ streamPos += len;
+ }
+
+ @Override
+ public int read() throws IOException {
+ bitOffset = 0; // Should reset
+
+ int res = raf.read();
+ if (res >= 0) {
+ streamPos++;
+ }
+
+ return res;
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ bitOffset = 0;
+
+ int numRead = raf.read(b, off, len);
+ if (numRead > 0) {
+ streamPos += numRead;
+ }
+
+ return numRead;
+ }
+
+ @Override
+ public void flushBefore(long pos) throws IOException {
+ long readFromPos = flushedPos;
+ super.flushBefore(pos);
+
+ long bytesToRead = pos - readFromPos;
+ raf.seek(readFromPos);
+
+ if (bytesToRead < MAX_BUFFER_LEN) {
+ byte buffer[] = new byte[(int)bytesToRead];
+ raf.readFully(buffer);
+ os.write(buffer);
+ } else {
+ byte buffer[] = new byte[MAX_BUFFER_LEN];
+ while (bytesToRead > 0) {
+ int count = (int) Math.min(MAX_BUFFER_LEN, bytesToRead);
+ raf.readFully(buffer, 0, count);
+ os.write(buffer, 0, count);
+ bytesToRead -= count;
+ }
+ }
+
+ os.flush();
+
+ if (pos != streamPos) {
+ raf.seek(streamPos); // Reset the position
+ }
+ }
+
+ @Override
+ public void seek(long pos) throws IOException {
+ if (pos < flushedPos) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ raf.seek(pos);
+ streamPos = raf.getFilePointer();
+ bitOffset = 0;
+ }
+
+ @Override
+ public long length() {
+ try {
+ return raf.length();
+ } catch(IOException e) {
+ return -1L;
+ }
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileCacheImageOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileImageInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileImageInputStream.java?view=auto&rev=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileImageInputStream.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileImageInputStream.java Thu Nov 23 00:29:16 2006
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package javax.imageio.stream;
+
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.io.File;
+import java.io.FileNotFoundException;
+
+public class FileImageInputStream extends ImageInputStreamImpl {
+ RandomAccessFile raf;
+
+ @SuppressWarnings({"DuplicateThrows"})
+ public FileImageInputStream(File f) throws FileNotFoundException, IOException {
+ if (f == null) {
+ throw new IllegalArgumentException("f == null!");
+ }
+
+ raf = new RandomAccessFile(f, "r");
+ }
+
+ public FileImageInputStream(RandomAccessFile raf) {
+ if (raf == null) {
+ throw new IllegalArgumentException("raf == null!");
+ }
+
+ this.raf = raf;
+ }
+
+ @Override
+ public int read() throws IOException {
+ bitOffset = 0;
+
+ int res = raf.read();
+ if (res != -1) {
+ streamPos++;
+ }
+ return res;
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ bitOffset = 0;
+
+ int numRead = raf.read(b, off, len);
+ if (numRead >= 0) {
+ streamPos += numRead;
+ }
+
+ return numRead;
+ }
+
+ @Override
+ public long length() {
+ try {
+ return raf.length();
+ } catch(IOException e) {
+ return -1L;
+ }
+ }
+
+ @Override
+ public void seek(long pos) throws IOException {
+ if (pos < getFlushedPosition()) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ raf.seek(pos);
+ streamPos = raf.getFilePointer();
+ bitOffset = 0;
+ }
+
+
+ @Override
+ public void close() throws IOException {
+ super.close();
+ raf.close();
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/FileImageInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/MemoryCacheImageInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/MemoryCacheImageInputStream.java?view=auto&rev=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/MemoryCacheImageInputStream.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/MemoryCacheImageInputStream.java Thu Nov 23 00:29:16 2006
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package javax.imageio.stream;
+
+import org.apache.harmony.x.imageio.stream.RandomAccessMemoryCache;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class MemoryCacheImageInputStream extends ImageInputStreamImpl {
+ private InputStream is;
+ private RandomAccessMemoryCache ramc = new RandomAccessMemoryCache();
+
+ public MemoryCacheImageInputStream(InputStream stream) throws IOException {
+ if (stream == null) {
+ throw new IllegalArgumentException("stream == null!");
+ }
+ is = stream;
+ }
+
+ @Override
+ public int read() throws IOException {
+ bitOffset = 0;
+
+ if (streamPos >= ramc.length()) {
+ int count = (int)(streamPos - ramc.length() + 1);
+ int bytesAppended = ramc.appendData(is, count);
+
+ if (bytesAppended < count) {
+ return -1;
+ }
+ }
+
+ int res = ramc.getData(streamPos);
+ if (res >= 0) {
+ streamPos++;
+ }
+ return res;
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ bitOffset = 0;
+
+ if (streamPos >= ramc.length()) {
+ int count = (int)(streamPos - ramc.length() + len);
+ ramc.appendData(is, count);
+ }
+
+ int res = ramc.getData(b, off, len, streamPos);
+ if (res > 0) {
+ streamPos += res;
+ }
+ return res;
+ }
+
+ @Override
+ public boolean isCached() {
+ return true;
+ }
+
+ @Override
+ public boolean isCachedFile() {
+ return false;
+ }
+
+ @Override
+ public boolean isCachedMemory() {
+ return true;
+ }
+
+ @Override
+ public void close() throws IOException {
+ super.close();
+ ramc.close();
+ }
+
+ @Override
+ public void flushBefore(long pos) throws IOException {
+ super.flushBefore(pos);
+ ramc.freeBefore(getFlushedPosition());
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/MemoryCacheImageInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/MemoryCacheImageOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/MemoryCacheImageOutputStream.java?view=auto&rev=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/MemoryCacheImageOutputStream.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/MemoryCacheImageOutputStream.java Thu Nov 23 00:29:16 2006
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package javax.imageio.stream;
+
+import org.apache.harmony.x.imageio.stream.RandomAccessMemoryCache;
+
+import java.io.OutputStream;
+import java.io.IOException;
+
+public class MemoryCacheImageOutputStream extends ImageOutputStreamImpl {
+ OutputStream os;
+ RandomAccessMemoryCache ramc = new RandomAccessMemoryCache();
+
+ public MemoryCacheImageOutputStream(OutputStream stream) {
+ if (stream == null) {
+ throw new IllegalArgumentException("stream == null!");
+ }
+ os = stream;
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ flushBits(); // See the flushBits method description
+
+ ramc.putData(b, streamPos);
+ streamPos++;
+ }
+
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException {
+ flushBits(); // See the flushBits method description
+
+ ramc.putData(b, off, len, streamPos);
+ streamPos += len;
+ }
+
+ @Override
+ public int read() throws IOException {
+ bitOffset = 0;
+
+ int res = ramc.getData(streamPos);
+ if (res >= 0) {
+ streamPos++;
+ }
+ return res;
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ bitOffset = 0;
+
+ int res = ramc.getData(b, off, len, streamPos);
+ if (res > 0) {
+ streamPos += res;
+ }
+ return res;
+ }
+
+ @Override
+ public long length() {
+ return ramc.length();
+ }
+
+ @Override
+ public boolean isCached() {
+ return true;
+ }
+
+ @Override
+ public boolean isCachedMemory() {
+ return true;
+ }
+
+ @Override
+ public boolean isCachedFile() {
+ return false;
+ }
+
+ @Override
+ public void close() throws IOException {
+ flushBefore(length());
+ super.close();
+ ramc.close();
+ }
+
+ @Override
+ public void flushBefore(long pos) throws IOException {
+ long flushedPosition = getFlushedPosition();
+ super.flushBefore(pos);
+
+ long newFlushedPosition = getFlushedPosition();
+ int nBytes = (int)(newFlushedPosition - flushedPosition);
+
+ ramc.getData(os, nBytes, flushedPosition);
+ ramc.freeBefore(newFlushedPosition);
+
+ os.flush();
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/javax/imageio/stream/MemoryCacheImageOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGSpiConsts.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGSpiConsts.java?view=diff&rev=478511&r1=478510&r2=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGSpiConsts.java (original)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/jpeg/JPEGSpiConsts.java Thu Nov 23 00:29:16 2006
@@ -27,8 +27,8 @@
public class JPEGSpiConsts {
private JPEGSpiConsts() {}
- static final String vendorName = "Intel Corporation";
- static final String version = "0.1 beta";
+ public static final String vendorName = "Intel Corporation";
+ public static final String version = "0.1 beta";
static final String readerClassName = "org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageReader";
static final String writerClassName = "org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageWriter";
Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReader.java?view=auto&rev=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReader.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReader.java Thu Nov 23 00:29:16 2006
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.harmony.x.imageio.plugins.png;
+
+import org.apache.harmony.awt.gl.image.DecodingImageSource;
+import org.apache.harmony.awt.gl.image.OffscreenImage;
+import org.apache.harmony.x.imageio.plugins.jpeg.IISDecodingImageSource;
+
+import javax.imageio.ImageReader;
+import javax.imageio.ImageTypeSpecifier;
+import javax.imageio.ImageReadParam;
+import javax.imageio.plugins.jpeg.JPEGImageReadParam;
+import javax.imageio.spi.ImageReaderSpi;
+import javax.imageio.stream.ImageInputStream;
+import javax.imageio.metadata.IIOMetadata;
+import java.io.IOException;
+import java.util.Iterator;
+import java.awt.image.BufferedImage;
+
+public class PNGImageReader extends ImageReader {
+ ImageInputStream iis;
+
+ public PNGImageReader(ImageReaderSpi imageReaderSpi) {
+ super(imageReaderSpi);
+ }
+
+ public int getNumImages(boolean allowSearch) throws IOException {
+ //-- TODO imlement
+ throw new UnsupportedOperationException("not implemented yet");
+ }
+
+ public int getWidth(int imageIndex) throws IOException {
+ //-- TODO imlement
+ throw new UnsupportedOperationException("not implemented yet");
+ }
+
+ public int getHeight(int imageIndex) throws IOException {
+ //-- TODO imlement
+ throw new UnsupportedOperationException("not implemented yet");
+ }
+
+ public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws IOException {
+ //-- TODO imlement
+ throw new UnsupportedOperationException("not implemented yet");
+ }
+
+ @Override
+ public IIOMetadata getStreamMetadata() throws IOException {
+ //-- TODO imlement
+ throw new UnsupportedOperationException("not implemented yet");
+ }
+
+ @Override
+ public IIOMetadata getImageMetadata(int imageIndex) throws IOException {
+ //-- TODO imlement
+ throw new UnsupportedOperationException("not implemented yet");
+ }
+
+ @Override
+ public BufferedImage read(int i, ImageReadParam imageReadParam) throws IOException {
+ if (iis == null) {
+ throw new IllegalArgumentException("input stream == null");
+ }
+
+ DecodingImageSource source = new IISDecodingImageSource(iis);
+ OffscreenImage image = new OffscreenImage(source);
+ source.addConsumer(image);
+ source.load();
+ return image.getBufferedImage();
+ }
+
+ @Override
+ public BufferedImage read(int i) throws IOException {
+ return read(i, null);
+ }
+
+ @Override
+ public void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata) {
+ super.setInput(input, seekForwardOnly, ignoreMetadata);
+ iis = (ImageInputStream) input;
+ }
+
+ @Override
+ public ImageReadParam getDefaultReadParam() {
+ return new ImageReadParam();
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReader.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReaderSpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReaderSpi.java?view=auto&rev=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReaderSpi.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReaderSpi.java Thu Nov 23 00:29:16 2006
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.harmony.x.imageio.plugins.png;
+
+import org.apache.harmony.x.imageio.plugins.jpeg.JPEGSpiConsts;
+
+import javax.imageio.spi.ImageReaderSpi;
+import javax.imageio.spi.ServiceRegistry;
+import javax.imageio.ImageReader;
+import javax.imageio.stream.ImageInputStream;
+import java.io.IOException;
+import java.util.Locale;
+
+public class PNGImageReaderSpi extends ImageReaderSpi {
+ static final String PNG_NAMES[] = new String[] {"png", "PNG"};
+ static final String PNG_SUFFIXES[] = new String[] {"png"};
+ static final String PNG_MIME_TYPES[] = new String[] {"image/png"};
+ static final String PNG_READER_CLASS_NAME = "org.apache.harmony.x.imageio.plugins.png.PNGImageReader";
+ static final String PNG_READER_SPI_NAMES[] = {"org.apache.harmony.x.imageio.plugins.png.PNGImageReaderSpi"};
+
+ public PNGImageReaderSpi() {
+ super(
+ JPEGSpiConsts.vendorName, JPEGSpiConsts.version,
+ PNG_NAMES, PNG_SUFFIXES,
+ PNG_MIME_TYPES, PNG_READER_CLASS_NAME,
+ STANDARD_INPUT_TYPE, null,
+ false, null,
+ null, null,
+ null, false,
+ null, null,
+ null, null
+ );
+ }
+
+ @Override
+ public boolean canDecodeInput(Object source) throws IOException {
+ ImageInputStream markable = (ImageInputStream) source;
+ markable.mark();
+
+ byte[] signature = new byte[8];
+ markable.seek(0);
+ markable.read(signature, 0, 8);
+ markable.reset();
+
+ // PNG signature: 137 80 78 71 13 10 26 10
+ return (signature[0] & 0xFF) == 137 &&
+ (signature[1] & 0xFF) == 80 &&
+ (signature[2] & 0xFF) == 78 &&
+ (signature[3] & 0xFF) == 71 &&
+ (signature[4] & 0xFF) == 13 &&
+ (signature[5] & 0xFF) == 10 &&
+ (signature[6] & 0xFF) == 26 &&
+ (signature[7] & 0xFF) == 10;
+ }
+
+ @Override
+ public ImageReader createReaderInstance(Object extension) throws IOException {
+ return new PNGImageReader(this);
+ }
+
+ @Override
+ public String getDescription(Locale locale) {
+ return "DRL PNG decoder";
+ }
+
+ @Override
+ public void onRegistration(ServiceRegistry registry, Class<?> category) {
+ super.onRegistration(registry, category);
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/plugins/png/PNGImageReaderSpi.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/FileIISSpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/FileIISSpi.java?view=diff&rev=478511&r1=478510&r2=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/FileIISSpi.java (original)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/FileIISSpi.java Thu Nov 23 00:29:16 2006
@@ -23,6 +23,7 @@
import javax.imageio.spi.ImageInputStreamSpi;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.FileImageOutputStream;
+import javax.imageio.stream.FileImageInputStream;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
@@ -40,7 +41,7 @@
public ImageInputStream createInputStreamInstance(Object input, boolean useCache,
File cacheDir) throws IOException {
if (File.class.isInstance(input)) {
- return new FileImageOutputStream((File) input);
+ return new FileImageInputStream((File) input);
}
throw new IllegalArgumentException("input is not an instance of java.io.File");
}
Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/InputStreamIISSpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/InputStreamIISSpi.java?view=auto&rev=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/InputStreamIISSpi.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/InputStreamIISSpi.java Thu Nov 23 00:29:16 2006
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.harmony.x.imageio.spi;
+
+import javax.imageio.spi.ImageInputStreamSpi;
+import javax.imageio.stream.*;
+import java.io.OutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Locale;
+
+public class InputStreamIISSpi extends ImageInputStreamSpi {
+ private static final String vendor = "Apache";
+
+ private static final String ver = "0.1";
+
+ public InputStreamIISSpi() {
+ super(vendor, ver, InputStream.class);
+ }
+
+ @Override
+ public String getDescription(Locale locale) {
+ return "Output Stream IOS Spi";
+ }
+
+ @Override
+ public boolean canUseCacheFile() {
+ return true;
+ }
+
+ @Override
+ public ImageInputStream createInputStreamInstance(Object input, boolean useCache, File cacheDir) throws IOException {
+ if (input instanceof InputStream) {
+ if (useCache) {
+ return new FileCacheImageInputStream((InputStream) input, cacheDir);
+ } else {
+ return new MemoryCacheImageInputStream((InputStream) input);
+ }
+ }
+ throw new IllegalArgumentException("Output is not an instance of InputStream");
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/InputStreamIISSpi.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/OutputStreamIOSSpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/OutputStreamIOSSpi.java?view=auto&rev=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/OutputStreamIOSSpi.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/OutputStreamIOSSpi.java Thu Nov 23 00:29:16 2006
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.harmony.x.imageio.spi;
+
+import javax.imageio.spi.ImageOutputStreamSpi;
+import javax.imageio.stream.ImageOutputStream;
+import javax.imageio.stream.FileCacheImageOutputStream;
+import javax.imageio.stream.MemoryCacheImageOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Locale;
+
+public class OutputStreamIOSSpi extends ImageOutputStreamSpi {
+ private static final String vendor = "Apache";
+
+ private static final String ver = "0.1";
+
+ public OutputStreamIOSSpi() {
+ super(vendor, ver, OutputStream.class);
+ }
+
+ @Override
+ public ImageOutputStream createOutputStreamInstance(Object output, boolean useCache, File cacheDir) throws IOException {
+ if (output instanceof OutputStream) {
+ if (useCache) {
+ return new FileCacheImageOutputStream((OutputStream) output, cacheDir);
+ } else {
+ return new MemoryCacheImageOutputStream((OutputStream) output);
+ }
+ }
+ throw new IllegalArgumentException("Output is not an instance of OutputStream");
+ }
+
+ @Override
+ public String getDescription(Locale locale) {
+ return "Output Stream IOS Spi";
+ }
+
+ @Override
+ public boolean canUseCacheFile() {
+ return true;
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/OutputStreamIOSSpi.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/RAFIISSpi.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/RAFIISSpi.java?view=diff&rev=478511&r1=478510&r2=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/RAFIISSpi.java (original)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/spi/RAFIISSpi.java Thu Nov 23 00:29:16 2006
@@ -22,7 +22,7 @@
import javax.imageio.spi.ImageInputStreamSpi;
import javax.imageio.stream.ImageInputStream;
-import javax.imageio.stream.FileImageOutputStream;
+import javax.imageio.stream.FileImageInputStream;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
@@ -41,7 +41,7 @@
public ImageInputStream createInputStreamInstance(Object input, boolean useCache,
File cacheDir) throws IOException {
if (RandomAccessFile.class.isInstance(input)) {
- return new FileImageOutputStream((RandomAccessFile) input);
+ return new FileImageInputStream((RandomAccessFile) input);
}
throw new IllegalArgumentException(
"input is not an instance of java.io.RandomAccessFile");
Added: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/stream/RandomAccessMemoryCache.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/stream/RandomAccessMemoryCache.java?view=auto&rev=478511
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/stream/RandomAccessMemoryCache.java (added)
+++ harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/stream/RandomAccessMemoryCache.java Thu Nov 23 00:29:16 2006
@@ -0,0 +1,226 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.harmony.x.imageio.stream;
+
+import java.util.ArrayList;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public final class RandomAccessMemoryCache {
+ private static final int BLOCK_SHIFT = 9;
+ private static final int BLOCK_SIZE = 1 << BLOCK_SHIFT;
+ private static final int BLOCK_MASK = BLOCK_SIZE - 1;
+
+ private long length;
+
+ private int firstUndisposed = 0;
+
+ private ArrayList<byte[]> blocks = new ArrayList<byte[]>();
+
+ public RandomAccessMemoryCache() {
+ }
+
+ public long length() {
+ return length;
+ }
+
+ public void close() {
+ blocks.clear();
+ length = 0;
+ }
+
+ private void grow(long pos) {
+ int blocksNeeded = (int)(pos >> BLOCK_SHIFT) - blocks.size() + 1;
+ for (int i=0; i < blocksNeeded; i++) {
+ blocks.add(new byte[BLOCK_SIZE]);
+ }
+
+ length = pos + 1;
+ }
+
+ public void putData(int oneByte, long pos) {
+ if (pos >= length) {
+ grow(pos);
+ }
+
+ byte[] block = blocks.get((int)(pos >> BLOCK_SHIFT));
+ block[(int)(pos & BLOCK_MASK)] = (byte) oneByte;
+ }
+
+ public void putData(byte[] buffer, int offset, int count, long pos) {
+ if (count > buffer.length - offset || count < 0 || offset < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (count == 0){
+ return;
+ }
+
+ long lastPos = pos + count - 1;
+ if (lastPos >= length) {
+ grow(lastPos);
+ }
+
+ while (count > 0) {
+ byte[] block = blocks.get((int)(pos >> BLOCK_SHIFT));
+ int blockOffset = (int)(pos & BLOCK_MASK);
+ int toCopy = Math.min(BLOCK_SIZE - blockOffset, count);
+ System.arraycopy(buffer, offset, block, blockOffset, toCopy);
+ pos += toCopy;
+ count -= toCopy;
+ offset += toCopy;
+ }
+ }
+
+ public int getData(long pos) {
+ if (pos >= length) {
+ return -1;
+ }
+
+ byte[] block = blocks.get((int)(pos >> BLOCK_SHIFT));
+ return block[(int)(pos & BLOCK_MASK)] & 0xFF;
+ }
+
+ public int getData(byte[] buffer, int offset, int count, long pos) {
+ if (count > buffer.length - offset || count < 0 || offset < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (count == 0) {
+ return 0;
+ }
+ if (pos >= length) {
+ return -1;
+ }
+
+ if (count + pos > length) {
+ count = (int) (length - pos);
+ }
+
+ byte[] block = blocks.get((int)(pos >> BLOCK_SHIFT));
+ int nbytes = Math.min(count, BLOCK_SIZE - (int)(pos & BLOCK_MASK));
+ System.arraycopy(block, (int)(pos & BLOCK_MASK), buffer, offset, nbytes);
+
+ return nbytes;
+ }
+ /*
+ public void seek(long pos) throws IOException {
+ if (pos < 0) {
+ throw new IOException("seek position is negative");
+ }
+ this.pos = pos;
+ }
+
+ public void readFully(byte[] buffer) throws IOException {
+ readFully(buffer, 0, buffer.length);
+ }
+
+ public void readFully(byte[] buffer, int offset, int count) throws IOException {
+ if (0 <= offset && offset <= buffer.length && 0 <= count && count <= buffer.length - offset) {
+ while (count > 0) {
+ int result = read(buffer, offset, count);
+ if (result >= 0) {
+ offset += result;
+ count -= result;
+ } else {
+ throw new EOFException();
+ }
+ }
+ } else {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ public long getFilePointer() {
+ return pos;
+ }
+*/
+
+ public void freeBefore(long pos) {
+ int blockIdx = (int)(pos >> BLOCK_SHIFT);
+ if (blockIdx <= firstUndisposed) { // Nothing to do
+ return;
+ }
+
+ for (int i = firstUndisposed; i < blockIdx; i++) {
+ blocks.set(i, null);
+ }
+
+ firstUndisposed = blockIdx;
+ }
+
+ public int appendData(InputStream is, int count) throws IOException {
+ if (count <= 0) {
+ return 0;
+ }
+
+ long startPos = length;
+ long lastPos = length + count - 1;
+ grow(lastPos); // Changes length
+
+ int blockIdx = (int)(startPos >> BLOCK_SHIFT);
+ int offset = (int) (startPos & BLOCK_MASK);
+
+ int bytesAppended = 0;
+
+ while (count > 0) {
+ byte[] block = blocks.get(blockIdx);
+ int toCopy = Math.min(BLOCK_SIZE - offset, count);
+ count -= toCopy;
+
+ while (toCopy > 0) {
+ int bytesRead = is.read(block, offset, toCopy);
+
+ if (bytesRead < 0) {
+ length -= (count - bytesAppended);
+ return bytesAppended;
+ }
+
+ toCopy -= bytesRead;
+ offset += bytesRead;
+ }
+
+ blockIdx++;
+ offset = 0;
+ }
+
+ return count;
+ }
+
+ public void getData(OutputStream os, int count, long pos) throws IOException {
+ if (pos + count > length) {
+ throw new IndexOutOfBoundsException("Argument out of cache");
+ }
+
+ int blockIdx = (int)(pos >> BLOCK_SHIFT);
+ int offset = (int) (pos & BLOCK_MASK);
+ if (blockIdx < firstUndisposed) {
+ throw new IndexOutOfBoundsException("The requested data are already disposed");
+ }
+
+ while (count > 0) {
+ byte[] block = blocks.get(blockIdx);
+ int toWrite = Math.min(BLOCK_SIZE - offset, count);
+ os.write(block, offset, toWrite);
+
+ blockIdx++;
+ offset = 0;
+ count -= toWrite;
+ }
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/imageio/src/main/java/org/apache/harmony/x/imageio/stream/RandomAccessMemoryCache.java
------------------------------------------------------------------------------
svn:eol-style = native