src/jdk.internal.vm.compiler/share/classes/jdk.internal.vm.compiler.libgraal/src/jdk/internal/vm/compiler/libgraal/OptionsEncoder.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54601 c40b2a190173
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    27 import java.io.ByteArrayInputStream;
    27 import java.io.ByteArrayInputStream;
    28 import java.io.ByteArrayOutputStream;
    28 import java.io.ByteArrayOutputStream;
    29 import java.io.DataInputStream;
    29 import java.io.DataInputStream;
    30 import java.io.DataOutputStream;
    30 import java.io.DataOutputStream;
    31 import java.io.IOException;
    31 import java.io.IOException;
    32 import java.util.HashMap;
    32 import java.util.LinkedHashMap;
    33 import java.util.Map;
    33 import java.util.Map;
    34 
    34 
    35 /**
    35 /**
    36  * Facilities for encoding/decoding a set of options to/from a byte array.
    36  * Facilities for encoding/decoding a set of options to/from a byte array.
    37  */
    37  */
   120      * Decodes {@code input} into a name/value map.
   120      * Decodes {@code input} into a name/value map.
   121      *
   121      *
   122      * @throws IllegalArgumentException if {@code input} cannot be decoded
   122      * @throws IllegalArgumentException if {@code input} cannot be decoded
   123      */
   123      */
   124     public static Map<String, Object> decode(byte[] input) {
   124     public static Map<String, Object> decode(byte[] input) {
   125         Map<String, Object> res = new HashMap<>();
   125         Map<String, Object> res = new LinkedHashMap<>();
   126         try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(input))) {
   126         try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(input))) {
   127             final int size = in.readInt();
   127             final int size = in.readInt();
   128             for (int i = 0; i < size; i++) {
   128             for (int i = 0; i < size; i++) {
   129                 final String key = in.readUTF();
   129                 final String key = in.readUTF();
   130                 final Object value;
   130                 final Object value;
   160                     default:
   160                     default:
   161                         throw new IllegalArgumentException("Unsupported value type: " + Integer.toHexString(type));
   161                         throw new IllegalArgumentException("Unsupported value type: " + Integer.toHexString(type));
   162                 }
   162                 }
   163                 res.put(key, value);
   163                 res.put(key, value);
   164             }
   164             }
       
   165             if (in.available() != 0) {
       
   166                 throw new IllegalArgumentException(in.available() + " undecoded bytes");
       
   167             }
   165         } catch (IOException ioe) {
   168         } catch (IOException ioe) {
   166             throw new IllegalArgumentException(ioe);
   169             throw new IllegalArgumentException(ioe);
   167         }
   170         }
   168         return res;
   171         return res;
   169     }
   172     }
   170 }
   173 }
   171