OSDN Git Service

auto import from //depot/cupcake/@135843
[android-x86/frameworks-native.git] / awt / org / apache / harmony / x / imageio / plugins / jpeg / IISDecodingImageSource.java
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17 /**
18  * @author Rustem Rafikov
19  * @version $Revision: 1.2 $
20  */
21 package org.apache.harmony.x.imageio.plugins.jpeg;
22
23 import javax.imageio.stream.ImageInputStream;
24
25 import org.apache.harmony.awt.gl.image.DecodingImageSource;
26
27 import java.io.InputStream;
28 import java.io.IOException;
29
30 /**
31  * This allows usage of the java2d jpegdecoder with ImageInputStream in
32  * the JPEGImageReader. Temporary, only to make JPEGImageReader#read(..)
33  * working.
34  *
35  */
36 public class IISDecodingImageSource extends DecodingImageSource {
37
38     private final InputStream is;
39
40     public IISDecodingImageSource(ImageInputStream iis) {
41         is = new IISToInputStreamWrapper(iis);
42     }
43
44     @Override
45     protected boolean checkConnection() {
46         return true;
47     }
48
49     @Override
50     protected InputStream getInputStream() {
51         return is;
52     }
53
54     static class IISToInputStreamWrapper extends InputStream {
55
56         private ImageInputStream input;
57
58         public IISToInputStreamWrapper(ImageInputStream input) {
59             this.input=input;
60         }
61
62         @Override
63         public int read() throws IOException {
64             return input.read();
65         }
66
67         @Override
68         public int read(byte[] b) throws IOException {
69             return input.read(b);
70         }
71
72         @Override
73         public int read(byte[] b, int off, int len) throws IOException {
74             return input.read(b, off, len);
75         }
76
77         @Override
78         public long skip(long n) throws IOException {
79             return input.skipBytes(n);
80         }
81
82         @Override
83         public boolean markSupported() {
84                 return true;  // This is orig
85                 
86             // ???AWT: FIXME
87                 // This is an error in Harmony. Not all input streams
88                 // have mark support and it is not ok to just return true. 
89                 // There should be an input.markSupported(). However, if 
90                 // this call returns false, nothing works anymore.
91                 
92                 // The backside is that BitmapFactory uses a call to markSupport()
93                 // to find out if it needs to warp the stream in a
94                 // BufferedInputStream to get mark support, and this fails!
95                 
96                 // Currently, the hack is in BitmapFactory, where we always
97                 // wrap the stream in a BufferedInputStream.
98         }
99
100         @Override
101         public void mark(int readlimit) {
102             input.mark();
103         }
104
105         @Override
106         public void reset() throws IOException {
107             input.reset();
108         }
109
110         @Override
111         public void close() throws IOException {
112             input.close();
113         }
114     }
115 }