Here you can find the source of getFileExtensionFromSource(byte[] picHeader)
public static String getFileExtensionFromSource(byte[] picHeader)
//package com.java2s; //License from project: Apache License public class Main { public static String getFileExtensionFromSource(byte[] picHeader) { String picExtendName = null; if (picHeader.length >= 2 && (picHeader[0] == 66) && (picHeader[1] == 77)) { //header bytes contains BM? picExtendName = "BMP"; } else if (picHeader.length >= 4 && (picHeader[1] == 80) && (picHeader[2] == 78) && (picHeader[3] == 71)) { //header bytes contains PNG? picExtendName = "PNG"; } else if (picHeader.length >= 6 && (picHeader[0] == 71) && (picHeader[1] == 73) && (picHeader[2] == 70) && (picHeader[3] == 56) && ((picHeader[4] == 55) || (picHeader[4] == 57)) && (picHeader[5] == 97)) { //header bytes contains GIF87a or GIF89a? picExtendName = "GIF"; } else if (picHeader.length >= 10 && (picHeader[6] == 74) && (picHeader[7] == 70) && (picHeader[8] == 73) && (picHeader[9] == 70)) { //header bytes contains JFIF? picExtendName = "JPG"; }//from w ww.j a va2s . c o m return picExtendName; } }