Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    /**
     * parse first frame buffer to retrieve file length
     *
     * @param fullFrame
     * @return
     */
    public static int getFileLength(byte[] fullFrame) {
        if (fullFrame.length > 6) {
            if (fullFrame[0] == 0x00 && fullFrame[1] == 0x00) {
                byte[] lengthBytes = Arrays.copyOfRange(fullFrame, 2, 6);
                int result = ((lengthBytes[3] & 0xFF) << 24) | ((lengthBytes[2] & 0xFF) << 16)
                        | ((lengthBytes[1] & 0xFF) << 8) | ((lengthBytes[0] & 0xFF) << 0);
                return result;
            } else {
                return -1;
            }
        }
        return -1;
    }
}