Faster and cleaner way to obtain UTF-8 encoded form.
Instead of specifying character encoding by name, the faster, cleaner, and safer way is to use StandardCharsets.UTF_8. Bug: 27461702 Change-Id: I897284d3ceeb44a21cc74de09a9b25f6aec8c205
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.android.apksigner.core.internal.jar;
|
package com.android.apksigner.core.internal.jar;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -220,11 +220,7 @@ public class ManifestParser {
|
|||||||
if (lineLengthBytes == 0) {
|
if (lineLengthBytes == 0) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
try {
|
return new String(mManifest, startOffset, lineLengthBytes, StandardCharsets.UTF_8);
|
||||||
return new String(mManifest, startOffset, lineLengthBytes, "UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new RuntimeException("UTF-8 character encoding not supported", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.apksigner.core.internal.jar;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
@@ -81,7 +82,7 @@ public abstract class ManifestWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void writeLine(OutputStream out, String line) throws IOException {
|
private static void writeLine(OutputStream out, String line) throws IOException {
|
||||||
byte[] lineBytes = line.getBytes("UTF-8");
|
byte[] lineBytes = line.getBytes(StandardCharsets.UTF_8);
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int remaining = lineBytes.length;
|
int remaining = lineBytes.length;
|
||||||
boolean firstLine = true;
|
boolean firstLine = true;
|
||||||
|
@@ -18,9 +18,9 @@ package com.android.apksigner.core.internal.zip;
|
|||||||
|
|
||||||
import com.android.apksigner.core.zip.ZipFormatException;
|
import com.android.apksigner.core.zip.ZipFormatException;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.nio.BufferUnderflowException;
|
import java.nio.BufferUnderflowException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -168,11 +168,7 @@ public class CentralDirectoryRecord {
|
|||||||
record.position(originalPosition);
|
record.position(originalPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
return new String(nameBytes, nameBytesOffset, nameLengthBytes, StandardCharsets.UTF_8);
|
||||||
return new String(nameBytes, nameBytesOffset, nameLengthBytes, "UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new RuntimeException("UTF-8 character encoding not supported", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ByLocalFileHeaderOffsetComparator
|
private static class ByLocalFileHeaderOffsetComparator
|
||||||
|
@@ -20,6 +20,7 @@ import java.io.Closeable;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.zip.DataFormatException;
|
import java.util.zip.DataFormatException;
|
||||||
import java.util.zip.Inflater;
|
import java.util.zip.Inflater;
|
||||||
|
|
||||||
@@ -93,7 +94,7 @@ public class LocalFileHeader {
|
|||||||
// exhibited when reading an APK for the purposes of verifying its signatures.
|
// exhibited when reading an APK for the purposes of verifying its signatures.
|
||||||
|
|
||||||
String entryName = cdRecord.getName();
|
String entryName = cdRecord.getName();
|
||||||
byte[] cdNameBytes = entryName.getBytes("UTF-8");
|
byte[] cdNameBytes = entryName.getBytes(StandardCharsets.UTF_8);
|
||||||
int headerSizeWithName = HEADER_SIZE_BYTES + cdNameBytes.length;
|
int headerSizeWithName = HEADER_SIZE_BYTES + cdNameBytes.length;
|
||||||
long localFileHeaderOffsetInArchive = cdRecord.getLocalFileHeaderOffset();
|
long localFileHeaderOffsetInArchive = cdRecord.getLocalFileHeaderOffset();
|
||||||
long headerEndInArchive = localFileHeaderOffsetInArchive + headerSizeWithName;
|
long headerEndInArchive = localFileHeaderOffsetInArchive + headerSizeWithName;
|
||||||
|
@@ -57,6 +57,7 @@ import java.io.OutputStream;
|
|||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.Key;
|
import java.security.Key;
|
||||||
import java.security.KeyFactory;
|
import java.security.KeyFactory;
|
||||||
@@ -717,7 +718,7 @@ class SignApk {
|
|||||||
// archive comment, so that tools that display the comment
|
// archive comment, so that tools that display the comment
|
||||||
// (hopefully) show something sensible.
|
// (hopefully) show something sensible.
|
||||||
// TODO: anything more useful we can put in this message?
|
// TODO: anything more useful we can put in this message?
|
||||||
byte[] message = "signed by SignApk".getBytes("UTF-8");
|
byte[] message = "signed by SignApk".getBytes(StandardCharsets.UTF_8);
|
||||||
temp.write(message);
|
temp.write(message);
|
||||||
temp.write(0);
|
temp.write(0);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user