Java InputStream Read getFileContent(InputStream inputStream)

Here you can find the source of getFileContent(InputStream inputStream)

Description

get File Content

License

Open Source License

Declaration

private static String getFileContent(InputStream inputStream) 

Method Source Code


//package com.java2s;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    private static String getFileContent(InputStream inputStream) {
        byte[] bytes = new byte[28];
        try {/* w  ww.  jav  a  2 s.c  o m*/
            inputStream.read(bytes, 0, 28);
        } catch (IOException e) {
            throw new RuntimeException("read file content error!");
        }
        return bytesToHexString(bytes);
    }

    private static String bytesToHexString(byte[] src) {
        if (null == src || src.length == 0)
            return null;
        StringBuilder sb = new StringBuilder();
        for (byte b : src) {
            String hv = Integer.toHexString(b & 0xFF);
            if (hv.length() < 2)
                sb.append(0);
            sb.append(hv);
        }
        return sb.toString();
    }
}

Related

  1. getFileContent(InputStream in)
  2. getFileContent(InputStream is)
  3. getFileContent(InputStream stream)
  4. getInputStream(Class clazz)
  5. getInputStream(Class ownerClass, String subName, String extension)