release/2.1.2 #24
|
@ -1,2 +1,3 @@
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
groovy.compiler.level=25
|
groovy.compiler.level=26
|
||||||
|
groovy.script.filters=**/*.dsld,y,**/*.gradle,n
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.minres.scviewer.ui;
|
||||||
|
public final class Hex {
|
||||||
|
public static byte[] decode(final String hex) {
|
||||||
|
if (hex.length() % 2 != 0) {
|
||||||
|
throw new IllegalArgumentException("A hex string must contain an even number of characters: " + hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] out = new byte[hex.length() / 2];
|
||||||
|
|
||||||
|
for (int i = 0; i < hex.length(); i += 2) {
|
||||||
|
int high = Character.digit(hex.charAt(i), 16);
|
||||||
|
int low = Character.digit(hex.charAt(i + 1), 16);
|
||||||
|
if (high == -1 || low == -1) {
|
||||||
|
throw new IllegalArgumentException("A hex string can only contain the characters 0-9, A-F, a-f: " + hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
out[i / 2] = (byte) (high * 16 + low);
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final char[] UPPER_HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', };
|
||||||
|
|
||||||
|
public static String encode(final byte[] bytes) {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder(bytes.length * 2);
|
||||||
|
for (byte cur : bytes) {
|
||||||
|
stringBuilder.append(UPPER_HEX_DIGITS[(cur >> 4) & 0xF]);
|
||||||
|
stringBuilder.append(UPPER_HEX_DIGITS[(cur & 0xF)]);
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Hex() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -71,7 +71,7 @@ public class TxEditorInputFactory implements IElementFactory {
|
||||||
String listData = memento.getString(TAG_STREAMLIST);
|
String listData = memento.getString(TAG_STREAMLIST);
|
||||||
if (listData != null) {
|
if (listData != null) {
|
||||||
try {
|
try {
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(javax.xml.bind.DatatypeConverter.parseHexBinary(listData));
|
ByteArrayInputStream bais = new ByteArrayInputStream(Hex.decode(listData));
|
||||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||||
Object obj = ois.readObject();
|
Object obj = ois.readObject();
|
||||||
if(obj instanceof List<?>)
|
if(obj instanceof List<?>)
|
||||||
|
@ -107,8 +107,9 @@ public class TxEditorInputFactory implements IElementFactory {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||||
oos.writeObject(input.getStreamNames());
|
oos.writeObject(input.getStreamNames());
|
||||||
memento.putString(TAG_STREAMLIST, javax.xml.bind.DatatypeConverter.printHexBinary(baos.toByteArray()));
|
memento.putString(TAG_STREAMLIST, Hex.encode(baos.toByteArray()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue