How to get MIME Type from a byte array in Java

Below example shows how to get the MimeType for a given byte[] using Java URLConnection.guessContentTypeFromStream() method

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URLConnection;

	public String getMimeType(byte data[]) throws Exception {		
		InputStream is = new BufferedInputStream(new ByteArrayInputStream(data));
		String mimeType = URLConnection.guessContentTypeFromStream(is);
		return mimeType
	}