Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.util.Log;
import java.io.File;
import java.io.FileInputStream;

public class Main {
    public static boolean isWAVFile(String fileName) {

        byte header[] = new byte[16];
        try {
            File f = new File(fileName);
            if (!f.exists()) {
                Log.d("OpusTool", fileName + ":" + "File does not exist.");
                return false;
            }
            long actualLength = f.length();
            FileInputStream io = new FileInputStream(f);
            io.read(header, 0, 16);
            io.close();

            String tag = new String(header, 0, 4) + new String(header, 8, 8);
            if (!tag.equals("RIFFWAVEfmt ")) {
                Log.d("OpusTool", fileName + ":" + "It's not a WAV file!");
                return false;
            }

            long paraLength = (header[4] & 0x000000ff) | ((header[5] << 8) & 0x0000ff00)
                    | ((header[6] << 16) & 0x00ff0000) | ((header[7] << 24) & 0xff000000);
            if (paraLength != actualLength - 8) {
                Log.d("OpusTool", fileName + ":" + "It might be a WAV file, but it's corrupted!");
                return false;
            }
            return true;

        } catch (Exception e) {
            Log.d("OpusTool", fileName + ":" + "File Error");
            return false;
        }
    }
}