FileDocCategorySizeDatePackage
IsoTypeReader.javaAPI Docmp4parser 1.0-RC-174568Wed Dec 19 20:10:38 GMT 2012com.coremedia.iso

IsoTypeReader

public final class IsoTypeReader extends Object

Fields Summary
Constructors Summary
Methods Summary
public static intbyte2int(byte b)

        return b < 0 ? b + 256 : b;
    
public static java.lang.Stringread4cc(java.nio.ByteBuffer bb)

        byte[] b = new byte[4];
        bb.get(b);
        return IsoFile.bytesToFourCC(b);
    
public static doublereadFixedPoint0230(java.nio.ByteBuffer bb)

        byte[] bytes = new byte[4];
        bb.get(bytes);

        int result = 0;
        result |= ((bytes[0] << 24) & 0xFF000000);
        result |= ((bytes[1] << 16) & 0xFF0000);
        result |= ((bytes[2] << 8) & 0xFF00);
        result |= ((bytes[3]) & 0xFF);
        return ((double) result) / (1 << 30);

    
public static doublereadFixedPoint1616(java.nio.ByteBuffer bb)

        byte[] bytes = new byte[4];
        bb.get(bytes);

        int result = 0;
        result |= ((bytes[0] << 24) & 0xFF000000);
        result |= ((bytes[1] << 16) & 0xFF0000);
        result |= ((bytes[2] << 8) & 0xFF00);
        result |= ((bytes[3]) & 0xFF);
        return ((double) result) / 65536;

    
public static floatreadFixedPoint88(java.nio.ByteBuffer bb)

        byte[] bytes = new byte[2];
        bb.get(bytes);
        short result = 0;
        result |= ((bytes[0] << 8) & 0xFF00);
        result |= ((bytes[1]) & 0xFF);
        return ((float) result) / 256;
    
public static java.lang.StringreadIso639(java.nio.ByteBuffer bb)

        int bits = readUInt16(bb);
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < 3; i++) {
            int c = (bits >> (2 - i) * 5) & 0x1f;
            result.append((char) (c + 0x60));
        }
        return result.toString();
    
public static java.lang.StringreadString(java.nio.ByteBuffer byteBuffer)
Reads a zero terminated UTF-8 string.

param
byteBuffer the data source
return
the string readByte
throws
Error in case of an error in the underlying stream


        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int read;
        while ((read = byteBuffer.get()) != 0) {
            out.write(read);
        }
        return Utf8.convert(out.toByteArray());
    
public static java.lang.StringreadString(java.nio.ByteBuffer byteBuffer, int length)

        byte[] buffer = new byte[length];
        byteBuffer.get(buffer);
        return Utf8.convert(buffer);

    
public static intreadUInt16(java.nio.ByteBuffer bb)

        int result = 0;
        result += byte2int(bb.get()) << 8;
        result += byte2int(bb.get());
        return result;
    
public static intreadUInt16BE(java.nio.ByteBuffer bb)

        int result = 0;
        result += byte2int(bb.get());
        result += byte2int(bb.get()) << 8;
        return result;
    
public static intreadUInt24(java.nio.ByteBuffer bb)

        int result = 0;
        result += readUInt16(bb) << 8;
        result += byte2int(bb.get());
        return result;
    
public static longreadUInt32(java.nio.ByteBuffer bb)

        long i = bb.getInt();
        if (i < 0) {
            i += 1l << 32;
        }
        return i;
    
public static longreadUInt32BE(java.nio.ByteBuffer bb)

        long ch1 = readUInt8(bb);
        long ch2 = readUInt8(bb);
        long ch3 = readUInt8(bb);
        long ch4 = readUInt8(bb);
        return ((ch4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1 << 0));

    
public static longreadUInt64(java.nio.ByteBuffer byteBuffer)

        long result = 0;
        // thanks to Erik Nicolas for finding a bug! Cast to long is definitivly needed
        result += readUInt32(byteBuffer) << 32;
        if (result < 0) {
            throw new RuntimeException("I don't know how to deal with UInt64! long is not sufficient and I don't want to use BigInt");
        }
        result += readUInt32(byteBuffer);

        return result;
    
public static intreadUInt8(java.nio.ByteBuffer bb)

        return byte2int(bb.get());