Android Byte Array to String Convert byteTOString(byte[] in, String encoding)

Here you can find the source of byteTOString(byte[] in, String encoding)

Description

byte TO String

Declaration

public static String byteTOString(byte[] in, String encoding)
        throws Exception 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {

    public static String byteTOString(byte[] in, String encoding)
            throws Exception {
        InputStream is = byteTOInputStream(in);
        return InputStreamTOString(is, encoding);
    }/*from  w  w w  .  jav  a 2  s .co  m*/

    public static InputStream byteTOInputStream(byte[] in) throws Exception {
        ByteArrayInputStream is = new ByteArrayInputStream(in);
        return is;
    }

    public static String InputStreamTOString(InputStream in, String encoding) {
        if (in == null) {
            return "";
        }
        try {
            StringBuilder sb = new StringBuilder();
            String line;
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(in, encoding));
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            return sb.toString();
        } catch (Exception e) {
            return "";
        } finally {
            try {
                in.close();
            } catch (IOException e) {
            }
        }
    }
}

Related

  1. byteTOString(byte[] in)
  2. byteTOString(byte[] in)
  3. byteTOString(byte[] in)
  4. byteTOString(byte[] in)
  5. byteTOString(byte[] in)
  6. byteToString(byte[] in)
  7. byteToString(int[] byteData)
  8. base16(byte[] data)
  9. ByteArrayToStringList(byte[] byteArray, int dataLength)