Here you can find the source of extractMimeType(byte[] imageData)
public static String extractMimeType(byte[] imageData) throws IOException
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.io.*; import java.net.URLConnection; public class Main { public static String extractMimeType(byte[] imageData) throws IOException { try (ByteArrayInputStream input = new ByteArrayInputStream(imageData)) { String contentType = URLConnection.guessContentTypeFromStream(input); return contentType != null ? contentType : "image/xyz"; }// www . j a va 2 s.c om } }