summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/camera/Storage.java10
-rw-r--r--src/com/android/camera/exif/ExifInterface.java7
-rw-r--r--src/com/android/camera/exif/ExifOutputStream.java13
-rw-r--r--src/com/android/camera/exif/OrderedDataOutputStream.java7
4 files changed, 30 insertions, 7 deletions
diff --git a/src/com/android/camera/Storage.java b/src/com/android/camera/Storage.java
index 53950f2..ab2f818 100644
--- a/src/com/android/camera/Storage.java
+++ b/src/com/android/camera/Storage.java
@@ -74,12 +74,12 @@ public class Storage {
}
}
- public static void writeFile(String path, byte[] jpeg, ExifInterface exif,
+ public static int writeFile(String path, byte[] jpeg, ExifInterface exif,
String mimeType) {
if (exif != null && (mimeType == null ||
mimeType.equalsIgnoreCase("jpeg"))) {
try {
- exif.writeExif(jpeg, path);
+ return exif.writeExif(jpeg, path);
} catch (Exception e) {
Log.e(TAG, "Failed to write data", e);
}
@@ -89,7 +89,9 @@ public class Storage {
dir.mkdirs();
}
writeFile(path, jpeg);
+ return jpeg.length;
}
+ return 0;
}
public static void writeFile(String path, byte[] data) {
@@ -114,9 +116,9 @@ public class Storage {
int height, String mimeType) {
String path = generateFilepath(title, mimeType);
- writeFile(path, jpeg, exif, mimeType);
+ int size = writeFile(path, jpeg, exif, mimeType);
return addImage(resolver, title, date, location, orientation,
- jpeg.length, path, width, height, mimeType);
+ size, path, width, height, mimeType);
}
// Get a ContentValues object for the given photo data
diff --git a/src/com/android/camera/exif/ExifInterface.java b/src/com/android/camera/exif/ExifInterface.java
index 340f19e..f353f35 100644
--- a/src/com/android/camera/exif/ExifInterface.java
+++ b/src/com/android/camera/exif/ExifInterface.java
@@ -850,14 +850,14 @@ public class ExifInterface {
* @throws FileNotFoundException
* @throws IOException
*/
- public void writeExif(byte[] jpeg, String exifOutFileName) throws FileNotFoundException,
+ public int writeExif(byte[] jpeg, String exifOutFileName) throws FileNotFoundException,
IOException {
if (jpeg == null || exifOutFileName == null) {
throw new IllegalArgumentException(NULL_ARGUMENT_STRING);
}
- OutputStream s = null;
+ ExifOutputStream s = null;
try {
- s = getExifWriterStream(exifOutFileName);
+ s = (ExifOutputStream) getExifWriterStream(exifOutFileName);
s.write(jpeg, 0, jpeg.length);
s.flush();
} catch (IOException e) {
@@ -865,6 +865,7 @@ public class ExifInterface {
throw e;
}
s.close();
+ return s.size();
}
/**
diff --git a/src/com/android/camera/exif/ExifOutputStream.java b/src/com/android/camera/exif/ExifOutputStream.java
index 191e828..90d4327 100644
--- a/src/com/android/camera/exif/ExifOutputStream.java
+++ b/src/com/android/camera/exif/ExifOutputStream.java
@@ -82,6 +82,8 @@ class ExifOutputStream extends FilterOutputStream {
private ByteBuffer mBuffer = ByteBuffer.allocate(4);
private final ExifInterface mInterface;
+ private int mSize = 0;
+
protected ExifOutputStream(OutputStream ou, ExifInterface iRef) {
super(new BufferedOutputStream(ou, STREAMBUFFER_SIZE));
mInterface = iRef;
@@ -127,6 +129,7 @@ class ExifOutputStream extends FilterOutputStream {
if (mByteToCopy > 0) {
int byteToProcess = length > mByteToCopy ? mByteToCopy : length;
out.write(buffer, offset, byteToProcess);
+ mSize += byteToProcess;
length -= byteToProcess;
mByteToCopy -= byteToProcess;
offset += byteToProcess;
@@ -147,6 +150,7 @@ class ExifOutputStream extends FilterOutputStream {
throw new IOException("Not a valid jpeg image, cannot write exif");
}
out.write(mBuffer.array(), 0, 2);
+ mSize += 2;
mState = STATE_FRAME_HEADER;
mBuffer.rewind();
writeExifData();
@@ -162,6 +166,7 @@ class ExifOutputStream extends FilterOutputStream {
short tag = mBuffer.getShort();
if (tag == JpegHeader.EOI) {
out.write(mBuffer.array(), 0, 2);
+ mSize += 2;
mBuffer.rewind();
}
}
@@ -175,9 +180,11 @@ class ExifOutputStream extends FilterOutputStream {
mState = STATE_JPEG_DATA;
} else if (!JpegHeader.isSofMarker(marker)) {
out.write(mBuffer.array(), 0, 4);
+ mSize += 4;
mByteToCopy = (mBuffer.getShort() & 0x0000ffff) - 2;
} else {
out.write(mBuffer.array(), 0, 4);
+ mSize += 4;
mState = STATE_JPEG_DATA;
}
mBuffer.rewind();
@@ -185,6 +192,7 @@ class ExifOutputStream extends FilterOutputStream {
}
if (length > 0) {
out.write(buffer, offset, length);
+ mSize += length;
}
}
@@ -238,6 +246,7 @@ class ExifOutputStream extends FilterOutputStream {
for (ExifTag t : nullTags) {
mExifData.addTag(t);
}
+ mSize += dataOutputStream.size();
}
private ArrayList<ExifTag> stripNullValueTags(ExifData data) {
@@ -515,4 +524,8 @@ class ExifOutputStream extends FilterOutputStream {
break;
}
}
+
+ int size() {
+ return mSize;
+ }
}
diff --git a/src/com/android/camera/exif/OrderedDataOutputStream.java b/src/com/android/camera/exif/OrderedDataOutputStream.java
index 1a1b31b..abc0a6e 100644
--- a/src/com/android/camera/exif/OrderedDataOutputStream.java
+++ b/src/com/android/camera/exif/OrderedDataOutputStream.java
@@ -24,6 +24,7 @@ import java.nio.ByteOrder;
class OrderedDataOutputStream extends FilterOutputStream {
private final ByteBuffer mByteBuffer = ByteBuffer.allocate(4);
+ private int mSize = 0;
public OrderedDataOutputStream(OutputStream out) {
super(out);
@@ -38,6 +39,7 @@ class OrderedDataOutputStream extends FilterOutputStream {
mByteBuffer.rewind();
mByteBuffer.putShort(value);
out.write(mByteBuffer.array(), 0, 2);
+ mSize += 2;
return this;
}
@@ -45,6 +47,7 @@ class OrderedDataOutputStream extends FilterOutputStream {
mByteBuffer.rewind();
mByteBuffer.putInt(value);
out.write(mByteBuffer.array());
+ mSize += 4;
return this;
}
@@ -53,4 +56,8 @@ class OrderedDataOutputStream extends FilterOutputStream {
writeInt((int) rational.getDenominator());
return this;
}
+
+ public int size() {
+ return mSize;
+ }
}