diff options
author | Victor Mocanu | 2017-10-06 16:05:34 +0200 |
---|---|---|
committer | Victor Mocanu | 2017-10-06 16:05:34 +0200 |
commit | 64138d179bf0d9d2a0a1bd288ed91609293a0c7d (patch) | |
tree | 5b28be69b3f3e29a7faed2626d3f5b05f1613e12 /src/main/java/org/openslx/util/vm/VmwareConfig.java | |
parent | [VBox] improved the create new tag and insert attribute functions (diff) | |
download | master-sync-shared-64138d179bf0d9d2a0a1bd288ed91609293a0c7d.tar.gz master-sync-shared-64138d179bf0d9d2a0a1bd288ed91609293a0c7d.tar.xz master-sync-shared-64138d179bf0d9d2a0a1bd288ed91609293a0c7d.zip |
[VBox] added new uuid when downloading vm from server
uuid is now writen in the vdi too
Diffstat (limited to 'src/main/java/org/openslx/util/vm/VmwareConfig.java')
-rw-r--r-- | src/main/java/org/openslx/util/vm/VmwareConfig.java | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/main/java/org/openslx/util/vm/VmwareConfig.java b/src/main/java/org/openslx/util/vm/VmwareConfig.java index 38db8a8..ab180e0 100644 --- a/src/main/java/org/openslx/util/vm/VmwareConfig.java +++ b/src/main/java/org/openslx/util/vm/VmwareConfig.java @@ -74,7 +74,7 @@ public class VmwareConfig } // function is used for both .vmx and .vmdk files - private void init( byte[] vmxContent, int length) throws UnsupportedVirtualizerFormatException + private void init( byte[] vmxContent, int length ) throws UnsupportedVirtualizerFormatException { try { boolean isValid = false; @@ -82,31 +82,32 @@ public class VmwareConfig String line; while ( ( line = reader.readLine() ) != null ) { KeyValuePair entry = parse( line ); - - + if ( entry != null ) { // TODO ask Simon which key is best for the check - if ( entry.key.equals("virtualHW.version") || entry.key.equals("ddb.virtualHWVersion")) { + if ( entry.key.equals( "virtualHW.version" ) || entry.key.equals( "ddb.virtualHWVersion" ) ) { isValid = true; - } - set( entry.key, unescape( entry.value ) ); + } + set( entry.key, unescape( entry.value ) ); } } - if (!isValid) { - throw new UnsupportedVirtualizerFormatException("not Vmware image format"); + if ( !isValid ) { + throw new UnsupportedVirtualizerFormatException( "not Vmware image format" ); } } catch ( IOException e ) { LOGGER.warn( "Exception when loading vmx from byte array (how!?)", e ); } } - public static BufferedReader getVmxReader( byte[] vmxContent, int length ) throws IOException { - Charset cs = getCharset(vmxContent, length); + public static BufferedReader getVmxReader( byte[] vmxContent, int length ) throws IOException + { + Charset cs = getCharset( vmxContent, length ); return new BufferedReader( new InputStreamReader( new ByteArrayInputStream( vmxContent, 0, length ), cs ) ); } - public static Charset getCharset( byte[] vmxContent, int length ) { + public static Charset getCharset( byte[] vmxContent, int length ) + { String csName = detectCharset( new ByteArrayInputStream( vmxContent, 0, length ) ); Charset cs = null; try { @@ -156,10 +157,8 @@ public class VmwareConfig return entries.entrySet(); } - private static final Pattern settingMatcher1 = Pattern.compile( "^\\s*(#?[a-z0-9\\.\\:_]+)\\s*=\\s*\"(.*)\"\\s*$", - Pattern.CASE_INSENSITIVE ); - private static final Pattern settingMatcher2 = Pattern.compile( "^\\s*(#?[a-z0-9\\.\\:_]+)\\s*=\\s*([^\"]*)\\s*$", - Pattern.CASE_INSENSITIVE ); + private static final Pattern settingMatcher1 = Pattern.compile( "^\\s*(#?[a-z0-9\\.\\:_]+)\\s*=\\s*\"(.*)\"\\s*$", Pattern.CASE_INSENSITIVE ); + private static final Pattern settingMatcher2 = Pattern.compile( "^\\s*(#?[a-z0-9\\.\\:_]+)\\s*=\\s*([^\"]*)\\s*$", Pattern.CASE_INSENSITIVE ); private static KeyValuePair parse( String line ) { @@ -170,8 +169,7 @@ public class VmwareConfig if ( !matcher.matches() ) { return null; } - return new KeyValuePair( - matcher.group( 1 ), matcher.group( 2 ) ); + return new KeyValuePair( matcher.group( 1 ), matcher.group( 2 ) ); } @@ -213,8 +211,7 @@ public class VmwareConfig StringBuilder sb = new StringBuilder( 300 ); for ( Entry<String, ConfigEntry> entry : entries.entrySet() ) { ConfigEntry value = entry.getValue(); - if ( ( !filteredRequired || value.forFiltered ) && - ( !generatedRequired || value.forGenerated ) ) { + if ( ( !filteredRequired || value.forFiltered ) && ( !generatedRequired || value.forGenerated ) ) { sb.append( entry.getKey() ); sb.append( " = \"" ); sb.append( value.getEscaped() ); |