/**
 * Copyright © 2014 Jan Seeger
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.alphadev.ntfslib.structures;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import net.alphadev.ntfslib.api.BlockDevice;
import net.alphadev.ntfslib.structures.Sector;

public class BootSector extends Sector {
    public static final int OEM_ID_OFFSET = 0x03;

    /**
     * The size of a boot sector in bytes.
     */
    public final static int SIZE = 512;

    private String oemId;
    private ExtendedBpb pbp;

    private BootSector(BlockDevice device) throws IOException {
        super(device, 0, SIZE);
        oemId = getString(OEM_ID_OFFSET, 8);
        pbp = new ExtendedBpb(super.buffer);
    }

    public static BootSector read(BlockDevice device) throws IOException {
        ByteBuffer bb = ByteBuffer.allocate(512);
        bb.order(ByteOrder.LITTLE_ENDIAN);
        device.read(0, bb);

        if ((bb.get(510) & 0xff) != 0x55 ||
                (bb.get(511) & 0xff) != 0xaa) throw new IOException(
                "missing boot sector signature");

        return new BootSector(device);
    }

    public ExtendedBpb getBootPartitionParameter() {
        return pbp;
    }

    public String getOemId() {
        return oemId;
    }
}

@@ -1014,16 +1014,22 @@
 private 
+final 
 String o
@@ -1046,16 +1046,22 @@
 private 
+final 
 Extended
@@ -1346,16 +1346,22 @@
         
+final 
 ByteBuff
@@ -1388,18 +1388,16 @@
 llocate(
-51
 2);%0A    
@@ -1455,16 +1455,18 @@
 ce.read(
+51
 0, bb);%0A
@@ -1486,18 +1486,16 @@
 (bb.get(
-51
 0) & 0xf
@@ -1532,18 +1532,16 @@
 (bb.get(
-51
 1) & 0xf

improve memory footprint.