com.drew.imaging.FileType Java Examples

The following examples show how to use com.drew.imaging.FileType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RiffTypeChecker.java    From metadata-extractor with Apache License 2.0 6 votes vote down vote up
@Override
public FileType checkType(byte[] bytes)
{
    String firstFour = new String(bytes, 0, 4);
    if (!firstFour.equals("RIFF"))
        return FileType.Unknown;

    String fourCC = new String(bytes, 8, 4);
    if (fourCC.equals("WAVE"))
        return FileType.Wav;
    if (fourCC.equals("AVI "))
        return FileType.Avi;
    if (fourCC.equals("WEBP"))
        return FileType.WebP;

    return FileType.Riff;
}
 
Example #2
Source File: MpegAudioTypeChecker.java    From metadata-extractor with Apache License 2.0 6 votes vote down vote up
@Override
public FileType checkType(byte[] bytes)
{
    // MPEG audio requires the first 11 bits to be set
    if (bytes[0] != (byte)0xFF || (bytes[1] & 0xE0) != 0xE0)
        return FileType.Unknown;

    // The MPEG Audio version ID value of 01 is reserved
    int version = (bytes[1] >> 3) & 3;
    if (version == 1)
        return FileType.Unknown;

    // The layer description value of 00 is reserved
    int layerDescription = (bytes[1] >> 1) & 3;
    if (layerDescription == 0)
        return FileType.Unknown;

    // The bitrate index value of 1111 is disallowed
    int bitrateIndex = bytes[2] >> 4;
    if (bitrateIndex == 0x0F)
        return FileType.Unknown;

    return FileType.Mp3;
}
 
Example #3
Source File: QuickTimeTypeChecker.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Override
public FileType checkType(byte[] bytes)
{
    String eightCC = new String(bytes, 4, 8);

    // Test at offset 4 for Base Media Format (i.e. QuickTime, MP4, etc...) identifier "ftyp" plus four identifying characters
    FileType t = _ftypMap.get(eightCC);
    if (t != null)
        return t;

    return FileType.Unknown;
}
 
Example #4
Source File: FileTypeDirectory.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
public FileTypeDirectory(FileType fileType)
{
    this.setDescriptor(new FileTypeDescriptor(this));

    setString(TAG_DETECTED_FILE_TYPE_NAME, fileType.getName());
    setString(TAG_DETECTED_FILE_TYPE_LONG_NAME, fileType.getLongName());

    if (fileType.getMimeType() != null)
        setString(TAG_DETECTED_FILE_MIME_TYPE, fileType.getMimeType());

    if (fileType.getCommonExtension() != null)
        setString(TAG_EXPECTED_FILE_NAME_EXTENSION, fileType.getCommonExtension());
}
 
Example #5
Source File: ProcessAllImagesInFolderUtility.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@NotNull
private static PrintWriter openWriter(@NotNull File file) throws IOException
{
    // Create the output directory if it doesn't exist
    File metadataDir = new File(String.format("%s/metadata", file.getParent()));
    if (!metadataDir.exists())
        metadataDir.mkdir();

    File javaDir = new File(String.format("%s/metadata/java", file.getParent()));
    if (!javaDir.exists())
        javaDir.mkdir();

    String outputPath = String.format("%s/metadata/java/%s.txt", file.getParent(), file.getName());
    Writer writer = new OutputStreamWriter(
        new FileOutputStream(outputPath),
        "UTF-8"
    );
    writer.write("FILE: " + file.getName() + NEW_LINE);

    // Detect file type
    BufferedInputStream stream = null;
    try {
        stream = new BufferedInputStream(new FileInputStream(file));
        FileType fileType = FileTypeDetector.detectFileType(stream);
        writer.write(String.format("TYPE: %s" + NEW_LINE, fileType.toString().toUpperCase()));
        writer.write(NEW_LINE);
    } finally {
        if (stream != null) {
            stream.close();
        }
    }

    return new PrintWriter(writer);
}