1 /* 2 * Copyright 2007, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.awt; 18 19 import java.io.IOException; 20 import java.io.OutputStream; 21 22 import javax.imageio.stream.ImageOutputStream; 23 24 public class ImageOutputStreamWrapper extends OutputStream { 25 26 protected ImageOutputStream mIos; 27 28 private byte[] mBuff; 29 30 public ImageOutputStreamWrapper(ImageOutputStream ios) { 31 if (null == ios) { 32 throw new IllegalArgumentException("ImageOutputStream must not be null"); 33 } 34 this.mIos = ios; 35 this.mBuff = new byte[1]; 36 } 37 38 public ImageOutputStream getImageOutputStream() { 39 return mIos; 40 } 41 42 @Override 43 public void write(int oneByte) throws IOException { 44 mBuff[0] = (byte)oneByte; 45 mIos.write(mBuff, 0, 1); 46 } 47 48 public void write(byte[] b) throws IOException { 49 mIos.write(b, 0, b.length); 50 } 51 52 public void write(byte[] b, int off, int len) throws IOException { 53 mIos.write(b, off, len); 54 } 55 56 public void flush() throws IOException { 57 mIos.flush(); 58 } 59 60 public void close() throws IOException { 61 if (mIos == null) { 62 throw new IOException("Stream already closed"); 63 } 64 mIos = null; 65 } 66 } 67