• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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.gallery3d.exif;
18 
19 import java.io.FilterOutputStream;
20 import java.io.IOException;
21 import java.io.OutputStream;
22 import java.nio.ByteBuffer;
23 import java.nio.ByteOrder;
24 
25 class OrderedDataOutputStream extends FilterOutputStream {
26     private final ByteBuffer mByteBuffer = ByteBuffer.allocate(4);
27 
OrderedDataOutputStream(OutputStream out)28     public OrderedDataOutputStream(OutputStream out) {
29         super(out);
30     }
31 
setByteOrder(ByteOrder order)32     public OrderedDataOutputStream setByteOrder(ByteOrder order) {
33         mByteBuffer.order(order);
34         return this;
35     }
36 
writeShort(short value)37     public OrderedDataOutputStream writeShort(short value) throws IOException {
38         mByteBuffer.rewind();
39         mByteBuffer.putShort(value);
40         out.write(mByteBuffer.array(), 0, 2);
41         return this;
42     }
43 
writeInt(int value)44     public OrderedDataOutputStream writeInt(int value) throws IOException {
45         mByteBuffer.rewind();
46         mByteBuffer.putInt(value);
47         out.write(mByteBuffer.array());
48         return this;
49     }
50 
writeRational(Rational rational)51     public OrderedDataOutputStream writeRational(Rational rational) throws IOException {
52         writeInt((int) rational.getNumerator());
53         writeInt((int) rational.getDenominator());
54         return this;
55     }
56 }
57