Skip to content

Commit

Permalink
#93 make the base64 algorithm more performant
Browse files Browse the repository at this point in the history
  • Loading branch information
therter committed May 13, 2024
1 parent 9a52df3 commit 69211ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/main/java/de/cismet/tools/Base64.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ public static byte[] toBase64(final byte[] byteString, final boolean wipeInput)
+ ((byteStringPadded[i + 1] & 0xFF) << 8)
+ (byteStringPadded[i + 2] & 0xFF);

byteStringPadded[i] = PasswordEncrypter.getWipe();
byteStringPadded[i + 1] = PasswordEncrypter.getWipe();
byteStringPadded[i + 2] = PasswordEncrypter.getWipe();
if (wipeInput) {
byteStringPadded[i] = PasswordEncrypter.getWipe();
byteStringPadded[i + 1] = PasswordEncrypter.getWipe();
byteStringPadded[i + 2] = PasswordEncrypter.getWipe();
}

base64[k++] = BASE64CODE[(j >> 18) & 0x3F];
base64[k++] = BASE64CODE[(j >> 12) & 0x3F];
Expand All @@ -100,7 +102,9 @@ public static byte[] toBase64(final byte[] byteString, final boolean wipeInput)
base64Br[j++] = LF;
}
base64Br[j] = base64[i];
base64[i] = PasswordEncrypter.getWipe();
if (wipeInput) {
base64[i] = PasswordEncrypter.getWipe();
}
}
for (int i = base64Br.length - 1; i > (base64Br.length - 1 - padding); --i) {
base64Br[i] = EQ;
Expand Down Expand Up @@ -175,10 +179,12 @@ public static byte[] fromBase64(final byte[] byteString, final boolean wipeInput
+ ((indexOf(strippedBr[i + 2]) & 0x3F) << 6)
+ (indexOf(strippedBr[i + 3]) & 0x3F);

strippedBr[i] = PasswordEncrypter.getWipe();
strippedBr[i + 1] = PasswordEncrypter.getWipe();
strippedBr[i + 2] = PasswordEncrypter.getWipe();
strippedBr[i + 3] = PasswordEncrypter.getWipe();
if (wipeInput) {
strippedBr[i] = PasswordEncrypter.getWipe();
strippedBr[i + 1] = PasswordEncrypter.getWipe();
strippedBr[i + 2] = PasswordEncrypter.getWipe();
strippedBr[i + 3] = PasswordEncrypter.getWipe();
}

decoded[k++] = (byte)((j >> 16) & 0xFF);
if ((i < (strippedBr.length - 4)) || (padding < 2)) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/de/cismet/tools/ExifReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.drew.metadata.MetadataException;
import com.drew.metadata.Tag;
import com.drew.metadata.exif.ExifIFD0Directory;
import com.drew.metadata.exif.ExifSubIFDDirectory;
import com.drew.metadata.exif.GpsDirectory;

import com.vividsolutions.jts.geom.Coordinate;
Expand Down Expand Up @@ -111,6 +112,18 @@ public Date getTimeDate() {
}
}

final ExifSubIFDDirectory subIfdDirectory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);

if (subIfdDirectory != null) {
if (ifdDirectory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL) != null) {
return ifdDirectory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL);
} else if (ifdDirectory.getDate(ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED) != null) {
return ifdDirectory.getDate(ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED);
} else if (ifdDirectory.getDate(ExifSubIFDDirectory.TAG_DATETIME) != null) {
return ifdDirectory.getDate(ExifSubIFDDirectory.TAG_DATETIME);
}
}

return null;
}

Expand Down

0 comments on commit 69211ed

Please sign in to comment.