1b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou/* 2b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou * Copyright (C) 2012 The Android Open Source Project 3b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou * 4b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou * Licensed under the Apache License, Version 2.0 (the "License"); 5b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou * you may not use this file except in compliance with the License. 6b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou * You may obtain a copy of the License at 7b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou * 8b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou * http://www.apache.org/licenses/LICENSE-2.0 9b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou * 10b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou * Unless required by applicable law or agreed to in writing, software 11b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou * distributed under the License is distributed on an "AS IS" BASIS, 12b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou * See the License for the specific language governing permissions and 14b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou * limitations under the License. 15b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou */ 16b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou 17b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Oupackage com.android.gallery3d.exif; 18b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou 19b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ouimport java.io.InputStream; 20b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ouimport java.nio.ByteBuffer; 21b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou 22b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ouclass ByteBufferInputStream extends InputStream { 23b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou 24b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou private ByteBuffer mBuf; 25b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou 26b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou public ByteBufferInputStream(ByteBuffer buf) { 27b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou mBuf = buf; 28b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou } 29b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou 30b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou @Override 31b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou public int read() { 32b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou if (!mBuf.hasRemaining()) { 33b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou return -1; 34b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou } 35b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou return mBuf.get() & 0xFF; 36b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou } 37b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou 38b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou @Override 39b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou public int read(byte[] bytes, int off, int len) { 40b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou if (!mBuf.hasRemaining()) { 41b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou return -1; 42b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou } 43b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou 44b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou len = Math.min(len, mBuf.remaining()); 45b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou mBuf.get(bytes, off, len); 46b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou return len; 47b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou } 48b430b34197d3016d1659ed104abbd3cb5d6d881dEarl Ou} 49