diff options
author | Victor Mocanu | 2017-07-12 15:11:29 +0200 |
---|---|---|
committer | Victor Mocanu | 2017-07-12 15:11:29 +0200 |
commit | 60781129a3f2c964bd454379f3706562d3824d71 (patch) | |
tree | a2504dbe8de478037dec80d8e2b60824e72ce3e4 /src/main/java/org/openslx/util/vm/DiskImage.java | |
parent | [VBox] Added the VBoxConfig class and done some work on the VBoxMetaData class (diff) | |
download | master-sync-shared-60781129a3f2c964bd454379f3706562d3824d71.tar.gz master-sync-shared-60781129a3f2c964bd454379f3706562d3824d71.tar.xz master-sync-shared-60781129a3f2c964bd454379f3706562d3824d71.zip |
[VBOX] exceptionhandling and added method to delete unwanted nodes in the config file
Diffstat (limited to 'src/main/java/org/openslx/util/vm/DiskImage.java')
-rw-r--r-- | src/main/java/org/openslx/util/vm/DiskImage.java | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/src/main/java/org/openslx/util/vm/DiskImage.java b/src/main/java/org/openslx/util/vm/DiskImage.java index 5f9756f..94d5d2c 100644 --- a/src/main/java/org/openslx/util/vm/DiskImage.java +++ b/src/main/java/org/openslx/util/vm/DiskImage.java @@ -54,31 +54,43 @@ public class DiskImage public final int hwVersion; public DiskImage( File disk ) throws FileNotFoundException, IOException, - UnknownImageFormatException, UnsupportedVirtualizerFormatException + UnknownImageFormatException { - // For now we only support VMDK... try ( RandomAccessFile file = new RandomAccessFile( disk, "r" ) ) { - if ( file.readInt() != VMDK_MAGIC ) - throw new UnknownImageFormatException(); - file.seek( 512 ); - byte[] buffer = new byte[ 2048 ]; - file.readFully( buffer ); - VmwareConfig config = new VmwareConfig( buffer, findNull( buffer ) ); - subFormat = config.get( "createType" ); - String parent = config.get( "parentCID" ); - this.isStandalone = isStandaloneCreateType( subFormat, parent ); - this.isCompressed = subFormat != null - && subFormat.equalsIgnoreCase( "streamOptimized" ); - this.isSnapshot = parent != null - && !parent.equalsIgnoreCase( "ffffffff" ); - this.format = ImageFormat.VMDK; - String hwv = config.get( "ddb.virtualHWVersion" ); - if (hwv == null ) { - this.hwVersion = 10; - } else { - this.hwVersion = Util.parseInt( hwv, 10 ); + // vmdk + if ( file.readInt() == VMDK_MAGIC ) { + file.seek( 512 ); + byte[] buffer = new byte[ 2048 ]; + file.readFully( buffer ); + VmwareConfig config; + try { + config = new VmwareConfig( buffer, findNull( buffer ) ); + } catch ( UnsupportedVirtualizerFormatException e ) { + config = null; + } + if (config != null) { + subFormat = config.get( "createType" ); + String parent = config.get( "parentCID" ); + this.isStandalone = isStandaloneCreateType( subFormat, parent ); + this.isCompressed = subFormat != null + && subFormat.equalsIgnoreCase( "streamOptimized" ); + this.isSnapshot = parent != null + && !parent.equalsIgnoreCase( "ffffffff" ); + this.format = ImageFormat.VMDK; + String hwv = config.get( "ddb.virtualHWVersion" ); + if (hwv == null ) { + this.hwVersion = 10; + } else { + this.hwVersion = Util.parseInt( hwv, 10 ); + } + return; + } } + // vdi + file.seek( 0 ); + // TODO } + throw new UnknownImageFormatException(); } private int findNull( byte[] buffer ) |