Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.util.Log;
import com.google.protobuf.ByteString;

public class Main {
    public static String ByteString2HexString(ByteString bytestring) {
        byte abyte0[] = ByteString2byteArray(bytestring);
        if (abyte0 == null)
            return null;
        else
            return byteArray2HexString(abyte0, abyte0.length);
    }

    public static byte[] ByteString2byteArray(ByteString bytestring) {
        int i = bytestring.size();
        if (i == 0) {
            return null;
        } else {
            byte abyte0[] = new byte[i];
            bytestring.copyTo(abyte0, 0, 0, i);
            return abyte0;
        }
    }

    public static String byteArray2HexString(byte abyte0[], int i) {
        int j = i;
        StringBuilder stringbuilder = new StringBuilder(i);
        if (abyte0.length < i) {
            Log.w("Util", "data length is shorter then print command length");
            j = abyte0.length;
        }
        int k = 0;
        do {
            if (k >= j)
                return stringbuilder.toString();
            Object aobj[] = new Object[1];
            aobj[0] = Byte.valueOf(abyte0[k]);
            stringbuilder.append(String.format("%02X ", aobj));
            k++;
        } while (true);
    }
}