diff options
Diffstat (limited to 'src/main/java/org/openslx/util/vm/VmwareConfig.java')
-rw-r--r-- | src/main/java/org/openslx/util/vm/VmwareConfig.java | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/main/java/org/openslx/util/vm/VmwareConfig.java b/src/main/java/org/openslx/util/vm/VmwareConfig.java index 18b60df..aa82419 100644 --- a/src/main/java/org/openslx/util/vm/VmwareConfig.java +++ b/src/main/java/org/openslx/util/vm/VmwareConfig.java @@ -75,17 +75,8 @@ public class VmwareConfig private void init( byte[] vmxContent, int length ) { - String csName = detectCharset( new ByteArrayInputStream( vmxContent, 0, length ) ); - Charset cs = null; try { - cs = Charset.forName( csName ); - } catch ( Exception e ) { - LOGGER.warn( "Could not instantiate charset " + csName, e ); - } - if ( cs == null ) - cs = StandardCharsets.ISO_8859_1; - try { - BufferedReader reader = new BufferedReader( new InputStreamReader( new ByteArrayInputStream( vmxContent, 0, length ), cs ) ); + BufferedReader reader = getVmxReader( vmxContent, length ); String line; while ( ( line = reader.readLine() ) != null ) { KeyValuePair entry = parse( line ); @@ -98,6 +89,20 @@ public class VmwareConfig } } + public static BufferedReader getVmxReader( byte[] vmxContent, int length ) throws IOException { + String csName = detectCharset( new ByteArrayInputStream( vmxContent, 0, length ) ); + Charset cs = null; + try { + cs = Charset.forName( csName ); + } catch ( Exception e ) { + LOGGER.warn( "Could not instantiate charset " + csName, e ); + } + if ( cs == null ) + cs = StandardCharsets.ISO_8859_1; + return new BufferedReader( new InputStreamReader( new ByteArrayInputStream( vmxContent, 0, length ), cs ) ); + + } + private String unescape( String value ) { String ret = value; @@ -110,7 +115,7 @@ public class VmwareConfig return ret; } - private String detectCharset( InputStream is ) + public static String detectCharset( InputStream is ) { try { BufferedReader csDetectReader = new BufferedReader( new InputStreamReader( is, StandardCharsets.ISO_8859_1 ) ); @@ -140,7 +145,7 @@ public class VmwareConfig private static final Pattern settingMatcher2 = Pattern.compile( "^\\s*(#?[a-z0-9\\.\\:_]+)\\s*=\\s*([^\"]*)\\s*$", Pattern.CASE_INSENSITIVE ); - private KeyValuePair parse( String line ) + private static KeyValuePair parse( String line ) { Matcher matcher = settingMatcher1.matcher( line ); if ( !matcher.matches() ) { |