/** * Converts bytes to long on input. */ public static long bytesToLong(byte b[]) { return bytesToLong(b, 0); }
public static long getManagementServerId(final byte[] bytes) { return NumbersUtil.bytesToLong(bytes, 16); }
public static long getAgentId(final byte[] bytes) { return NumbersUtil.bytesToLong(bytes, 24); }
public static long getViaAgentId(final byte[] bytes) { return NumbersUtil.bytesToLong(bytes, 32); }
public static long getSequence(final byte[] bytes) { return NumbersUtil.bytesToLong(bytes, 4); }
protected long getTemplateVirtualSize(File file) throws IOException { byte[] b = new byte[8]; try (FileInputStream strm = new FileInputStream(file)) { if (strm.skip(VIRTUALSIZE_HEADER_LOCATION) != VIRTUALSIZE_HEADER_LOCATION) { throw new IOException("Unable to skip to the virtual size header"); } if (strm.read(b) != 8) { throw new IOException("Unable to properly read the size"); } } return NumbersUtil.bytesToLong(b); }
/** * @param inputStream The QCOW2 object in stream format. * @return The virtual size of the QCOW2 object. */ public static long getVirtualSize(InputStream inputStream) throws IOException { byte[] bytes = new byte[VIRTUALSIZE_HEADER_LENGTH]; if (inputStream.skip(VIRTUALSIZE_HEADER_LOCATION) != VIRTUALSIZE_HEADER_LOCATION) { throw new IOException("Unable to skip to the virtual size header"); } if (inputStream.read(bytes) != VIRTUALSIZE_HEADER_LENGTH) { throw new IOException("Unable to properly read the size"); } return NumbersUtil.bytesToLong(bytes); } }
return NumbersUtil.bytesToLong(currentSize);
@Test public void bytesToLong() { assertEquals(0, NumbersUtil.bytesToLong(new byte[] {0, 0, 0, 0, 0, 0, 0, 0})); assertEquals(1, NumbersUtil.bytesToLong(new byte[] {0, 0, 0, 0, 0, 0, 0, 1})); assertEquals(257, NumbersUtil.bytesToLong(new byte[] {0, 0, 0, 0, 0, 0, 1, 1})); }
/** * Converts bytes to long on input. */ public static long bytesToLong(final byte[] b) { return bytesToLong(b, 0); }
public static long getAgentId(final byte[] bytes) { return NumbersUtil.bytesToLong(bytes, 24); }
public static long getSequence(final byte[] bytes) { return NumbersUtil.bytesToLong(bytes, 4); }
public static long getViaAgentId(final byte[] bytes) { return NumbersUtil.bytesToLong(bytes, 32); }
public static long getManagementServerId(final byte[] bytes) { return NumbersUtil.bytesToLong(bytes, 16); }
protected long getTemplateVirtualSize(final File file) throws IOException { final byte[] b = new byte[8]; try (final FileInputStream strm = new FileInputStream(file)) { if (strm.skip(VIRTUALSIZE_HEADER_LOCATION) != VIRTUALSIZE_HEADER_LOCATION) { throw new IOException("Unable to skip to the virtual size header"); } if (strm.read(b) != 8) { throw new IOException("Unable to properly read the size"); } } return NumbersUtil.bytesToLong(b); }
/** * @param inputStream The QCOW2 object in stream format. * @return The virtual size of the QCOW2 object. */ public static long getVirtualSize(final InputStream inputStream) throws IOException { final byte[] bytes = new byte[VIRTUALSIZE_HEADER_LENGTH]; if (inputStream.skip(VIRTUALSIZE_HEADER_LOCATION) != VIRTUALSIZE_HEADER_LOCATION) { throw new IOException("Unable to skip to the virtual size header"); } if (inputStream.read(bytes) != VIRTUALSIZE_HEADER_LENGTH) { throw new IOException("Unable to properly read the size"); } return NumbersUtil.bytesToLong(bytes); } }
protected long getTemplateVirtualSize(final File file) throws IOException { final byte[] currentSize = new byte[8]; final byte[] creatorApp = new byte[4]; try (final FileInputStream strm = new FileInputStream(file)) { long skipped = strm.skip(file.length() - this.vhdFooterSize + this.vhdFooterCreatorAppOffset); if (skipped == -1) { throw new IOException("Unexpected end-of-file"); } long read = strm.read(creatorApp); if (read == -1) { throw new IOException("Unexpected end-of-file"); } skipped = strm.skip(this.vhdFooterCurrentSizeOffset - this.vhdFooterCreatorVerOffset); if (skipped == -1) { throw new IOException("Unexpected end-of-file"); } read = strm.read(currentSize); if (read == -1) { throw new IOException("Unexpected end-of-file"); } } return NumbersUtil.bytesToLong(currentSize); }
@Test public void bytesToLong() { assertEquals(0, NumbersUtil.bytesToLong(new byte[]{0, 0, 0, 0, 0, 0, 0, 0})); assertEquals(1, NumbersUtil.bytesToLong(new byte[]{0, 0, 0, 0, 0, 0, 0, 1})); assertEquals(257, NumbersUtil.bytesToLong(new byte[]{0, 0, 0, 0, 0, 0, 1, 1})); } }