Android File Extension Name Get getFileExtensionFromSource(byte[] picHeader)

Here you can find the source of getFileExtensionFromSource(byte[] picHeader)

Description

get File Extension From Source

License

Apache License

Declaration

public static String getFileExtensionFromSource(byte[] picHeader) 

Method Source Code

//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;
    }
}

Related

  1. getFileExtension(String file)
  2. getFileExtension(String fileName)
  3. getFileExtension(String filename)
  4. getFileExtension(String filename, String defExt)
  5. getFileExtensionFromName(String filename)
  6. getFileExtensionFromUrl(String url)
  7. getFilenameExtension(String path)
  8. getNameMinusExtension(File file)
  9. getPathExtension(final String path)