Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98b4f07d authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Faster and cleaner way to obtain UTF-8 encoded form."

parents 6c0c7203 d4761a19
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package com.android.apksigner.core.internal.jar;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -220,11 +220,7 @@ public class ManifestParser {
        if (lineLengthBytes == 0) {
            return "";
        }
        try {
            return new String(mManifest, startOffset, lineLengthBytes, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("UTF-8 character encoding not supported", e);
        }
        return new String(mManifest, startOffset, lineLengthBytes, StandardCharsets.UTF_8);
    }


+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.apksigner.core.internal.jar;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
@@ -81,7 +82,7 @@ public abstract class ManifestWriter {
    }

    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 remaining = lineBytes.length;
        boolean firstLine = true;
+2 −6
Original line number Diff line number Diff line
@@ -18,9 +18,9 @@ package com.android.apksigner.core.internal.zip;

import com.android.apksigner.core.zip.ZipFormatException;

import java.io.UnsupportedEncodingException;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Comparator;

/**
@@ -168,11 +168,7 @@ public class CentralDirectoryRecord {
                record.position(originalPosition);
            }
        }
        try {
            return new String(nameBytes, nameBytesOffset, nameLengthBytes, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("UTF-8 character encoding not supported", e);
        }
        return new String(nameBytes, nameBytesOffset, nameLengthBytes, StandardCharsets.UTF_8);
    }

    private static class ByLocalFileHeaderOffsetComparator
+2 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import java.io.Closeable;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;

@@ -93,7 +94,7 @@ public class LocalFileHeader {
        // exhibited when reading an APK for the purposes of verifying its signatures.

        String entryName = cdRecord.getName();
        byte[] cdNameBytes = entryName.getBytes("UTF-8");
        byte[] cdNameBytes = entryName.getBytes(StandardCharsets.UTF_8);
        int headerSizeWithName = HEADER_SIZE_BYTES + cdNameBytes.length;
        long localFileHeaderOffsetInArchive = cdRecord.getLocalFileHeaderOffset();
        long headerEndInArchive = localFileHeaderOffsetInArchive + headerSizeWithName;
+2 −1
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.Key;
import java.security.KeyFactory;
@@ -717,7 +718,7 @@ class SignApk {
        // archive comment, so that tools that display the comment
        // (hopefully) show something sensible.
        // 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(0);