@Test public void testGetSingleExtentSize() throws Exception { File file = new File(VmdkMetadataTest.class.getResource("/vmdk/good.vmdk").getPath()); fis = new BufferedInputStream(new FileInputStream(file)); assertThat(VmdkMetadata.getSingleExtentSize(fis), is(4096)); file = new File(VmdkMetadataTest.class.getResource("/vmdk/good-space.vmdk").getPath()); fis = new BufferedInputStream(new FileInputStream(file)); assertThat(VmdkMetadata.getSingleExtentSize(fis), is(4096)); }
public static int getSingleExtentSize(InputStream inputStream) throws IOException { String s = DataField.getString(new DataField(0, 100000), inputStream); int beg = s.indexOf(EXTENT_DESCRIPTION_HEADER); if (beg < 0) { logger.error("Invalid vmdk: missing {}\n{}", EXTENT_DESCRIPTION_HEADER, s); throw new IllegalStateException("Invalid vmdk: missing " + EXTENT_DESCRIPTION_HEADER); } int end = s.indexOf(DISK_DATA_BASE_HEADER, beg); if (end < 0) { logger.error("Invalid vmdk: missing {}\n{}", DISK_DATA_BASE_HEADER, s); throw new IllegalStateException("Invalid vmdk: missing " + DISK_DATA_BASE_HEADER); } s = s.substring(beg + EXTENT_DESCRIPTION_HEADER.length(), end).trim(); if (s.indexOf("\n") >= 0) { logger.error("Invalid vmdk: multiple vmdks detected\n{}", s); throw new IllegalStateException("Invalid vmdk: multiple vmdks detected"); } List<String> fields = extractExtentFields(s); if (fields.size() != 4) { logger.error("Invalid vmdk: fields length is {}\n{}", fields.size(), s); throw new IllegalStateException("Invalid vmdk: fields length is " + fields.size()); } try { return Integer.parseInt(fields.get(1)); } catch (NumberFormatException e) { logger.error("Invalid string: second field is not integer\n{}", s); throw new IllegalStateException("Invalid string: second field is not integer", e); } }
VmdkMetadata { public static int getSingleExtentSize(InputStream inputStream) throws IOException { String s = DataField.getString(new DataField(0, 100000), inputStream); int beg = s.indexOf(EXTENT_DESCRIPTION_HEADER); if (beg < 0) { logger.error("Invalid vmdk: missing {}\n{}", EXTENT_DESCRIPTION_HEADER, s); throw new IllegalStateException("Invalid vmdk: missing " + EXTENT_DESCRIPTION_HEADER); } int end = s.indexOf(DISK_DATA_BASE_HEADER, beg); if (end < 0) { logger.error("Invalid vmdk: missing {}\n{}", DISK_DATA_BASE_HEADER, s); throw new IllegalStateException("Invalid vmdk: missing " + DISK_DATA_BASE_HEADER); } s = s.substring(beg + EXTENT_DESCRIPTION_HEADER.length(), end).trim(); if (s.indexOf("\n") >= 0) { logger.error("Invalid vmdk: multiple vmdks detected\n{}", s); throw new IllegalStateException("Invalid vmdk: multiple vmdks detected"); } List<String> fields = extractExtentFields(s); if (fields.size() != 4) { logger.error("Invalid vmdk: fields length is {}\n{}", fields.size(), s); throw new IllegalStateException("Invalid vmdk: fields length is " + fields.size()); } try { return Integer.parseInt(fields.get(1)); } catch (NumberFormatException e) { logger.error("Invalid string: second field is not integer\n{}", s); throw new IllegalStateException("Invalid string: second field is not integer", e); } } }
VmdkMetadata { public static int getSingleExtentSize(InputStream inputStream) throws IOException { String s = DataField.getString(new DataField(0, 100000), inputStream); int beg = s.indexOf(EXTENT_DESCRIPTION_HEADER); if (beg < 0) { logger.error("Invalid vmdk: missing {}\n{}", EXTENT_DESCRIPTION_HEADER, s); throw new IllegalStateException("Invalid vmdk: missing " + EXTENT_DESCRIPTION_HEADER); } int end = s.indexOf(DISK_DATA_BASE_HEADER, beg); if (end < 0) { logger.error("Invalid vmdk: missing {}\n{}", DISK_DATA_BASE_HEADER, s); throw new IllegalStateException("Invalid vmdk: missing " + DISK_DATA_BASE_HEADER); } s = s.substring(beg + EXTENT_DESCRIPTION_HEADER.length(), end).trim(); if (s.indexOf("\n") >= 0) { logger.error("Invalid vmdk: multiple vmdks detected\n{}", s); throw new IllegalStateException("Invalid vmdk: multiple vmdks detected"); } List<String> fields = extractExtentFields(s); if (fields.size() != 4) { logger.error("Invalid vmdk: fields length is {}\n{}", fields.size(), s); throw new IllegalStateException("Invalid vmdk: fields length is " + fields.size()); } try { return Integer.parseInt(fields.get(1)); } catch (NumberFormatException e) { logger.error("Invalid string: second field is not integer\n{}", s); throw new IllegalStateException("Invalid string: second field is not integer", e); } }  }
VmdkMetadata { public static int getSingleExtentSize(InputStream inputStream) throws IOException { String s = DataField.getString(new DataField(0, 100000), inputStream); int beg = s.indexOf(EXTENT_DESCRIPTION_HEADER); if (beg < 0) { logger.error("Invalid vmdk: missing {}\n{}", EXTENT_DESCRIPTION_HEADER, s); throw new IllegalStateException("Invalid vmdk: missing " + EXTENT_DESCRIPTION_HEADER); } int end = s.indexOf(DISK_DATA_BASE_HEADER, beg); if (end < 0) { logger.error("Invalid vmdk: missing {}\n{}", DISK_DATA_BASE_HEADER, s); throw new IllegalStateException("Invalid vmdk: missing " + DISK_DATA_BASE_HEADER); } s = s.substring(beg + EXTENT_DESCRIPTION_HEADER.length(), end).trim(); if (s.indexOf("\n") >= 0) { logger.error("Invalid vmdk: multiple vmdks detected\n{}", s); throw new IllegalStateException("Invalid vmdk: multiple vmdks detected"); } List<String> fields = extractExtentFields(s); if (fields.size() != 4) { logger.error("Invalid vmdk: fields length is {}\n{}", fields.size(), s); throw new IllegalStateException("Invalid vmdk: fields length is " + fields.size()); } try { return Integer.parseInt(fields.get(1)); } catch (NumberFormatException e) { logger.error("Invalid string: second field is not integer\n{}", s); throw new IllegalStateException("Invalid string: second field is not integer", e); } }  static int getSingleExtentSize(InputStream inputStream); static List<String> extractExtentFields(String extentDescription); }
VmdkMetadata { public static int getSingleExtentSize(InputStream inputStream) throws IOException { String s = DataField.getString(new DataField(0, 100000), inputStream); int beg = s.indexOf(EXTENT_DESCRIPTION_HEADER); if (beg < 0) { logger.error("Invalid vmdk: missing {}\n{}", EXTENT_DESCRIPTION_HEADER, s); throw new IllegalStateException("Invalid vmdk: missing " + EXTENT_DESCRIPTION_HEADER); } int end = s.indexOf(DISK_DATA_BASE_HEADER, beg); if (end < 0) { logger.error("Invalid vmdk: missing {}\n{}", DISK_DATA_BASE_HEADER, s); throw new IllegalStateException("Invalid vmdk: missing " + DISK_DATA_BASE_HEADER); } s = s.substring(beg + EXTENT_DESCRIPTION_HEADER.length(), end).trim(); if (s.indexOf("\n") >= 0) { logger.error("Invalid vmdk: multiple vmdks detected\n{}", s); throw new IllegalStateException("Invalid vmdk: multiple vmdks detected"); } List<String> fields = extractExtentFields(s); if (fields.size() != 4) { logger.error("Invalid vmdk: fields length is {}\n{}", fields.size(), s); throw new IllegalStateException("Invalid vmdk: fields length is " + fields.size()); } try { return Integer.parseInt(fields.get(1)); } catch (NumberFormatException e) { logger.error("Invalid string: second field is not integer\n{}", s); throw new IllegalStateException("Invalid string: second field is not integer", e); } }  static int getSingleExtentSize(InputStream inputStream); static List<String> extractExtentFields(String extentDescription);  }