package org.openslx.dnbd3; import java.nio.ByteBuffer; public class DNBD3Header { public static final int ERROR_FILE_NOT_FOUND = 1; public static final int ERROR_IMAGE_ALREADY_EXISTS = 2; public static final int ERROR_CONFIG_FILE_PERMISSIONS = 3; public static final int ERROR_IMAGE_NOT_FOUND = 4; public static final int ERROR_RID = 5; public static final int ERROR_IMAGE_IN_USE = 6; public static final int ERROR_UNKNOWN = 10; private int cmd; private int size; private int error; public DNBD3Header(int cmd, int size, int error) { this.cmd = cmd; this.size = size; this.error = error; } public DNBD3Header(byte[] bytes) { ByteBuffer bb = ByteBuffer.wrap(bytes); this.cmd = bb.getInt(); this.size = bb.getInt(); this.error = bb.getInt(); } public DNBD3Header() { } public byte[] toByteArray() { ByteBuffer bb = ByteBuffer.allocate(12); bb.putInt(cmd); bb.putInt(size); bb.putInt(error); return bb.array(); } public void fromByteArray(byte[] bytes) { ByteBuffer bb = ByteBuffer.wrap(bytes); this.cmd = bb.getInt(); this.size = bb.getInt(); this.error = bb.getInt(); } public int getCmd() { return cmd; } public void setCmd(int cmd) { this.cmd = cmd; } public int getSize() { return size; } public void setSize(int size) { this.size = size; } public int getError() { return error; } public void setError(int error) { this.error = error; } }