Skip to content

Commit

Permalink
Remove dependency on JAXB package.
Browse files Browse the repository at this point in the history
From Java 9 on the JAXB related packages have been found to be JavaEE
rather than part of the JavaSE distribution. Therefore relying on them
breaks our client in Java 9+ environments.
  • Loading branch information
mcgaerty committed Sep 26, 2018
1 parent 4a0d138 commit b901961
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 17 deletions.
64 changes: 62 additions & 2 deletions src/main/java/bwfdm/replaydh/utils/RDHUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,73 @@ public static String getCompleteDisplayName(Identifiable identifiable) {

public static String replaceNotAllowedCharacters(final String str) {
String output = new String(str);

// Needed for Apache server!
output = output.replace("\\", "/");
output = output.replace(" ", "_"); //TODO: replace with "%20" ??

return output;
}


/**
* Converts the string argument into an array of bytes.
*
* @param s
* @return
*/
public static byte[] parseHexBinary(String s) {
final int len = s.length();

// "111" is not a valid hex encoding.
if (len % 2 != 0) {
throw new IllegalArgumentException("hexBinary needs to be even-length: " + s);
}

byte[] out = new byte[len / 2];

for (int i = 0; i < len; i += 2) {
int h = hexToBin(s.charAt(i));
int l = hexToBin(s.charAt(i + 1));
if (h == -1 || l == -1) {
throw new IllegalArgumentException("contains illegal character for hexBinary: " + s);
}

out[i / 2] = (byte) (h * 16 + l);
}

return out;
}

private static int hexToBin(char ch) {
if ('0' <= ch && ch <= '9') {
return ch - '0';
}
if ('A' <= ch && ch <= 'F') {
return ch - 'A' + 10;
}
if ('a' <= ch && ch <= 'f') {
return ch - 'a' + 10;
}
return -1;
}

private static final char[] hexCode = "0123456789ABCDEF".toCharArray();

/**
* Converts an array of bytes into a string.
*
* @param data
* @return
*/
public static String printHexBinary(byte[] data) {
StringBuilder r = new StringBuilder(data.length * 2);
for (byte b : data) {
r.append(hexCode[(b >> 4) & 0xF]);
r.append(hexCode[(b & 0xF)]);
}
return r.toString();
}
}


30 changes: 15 additions & 15 deletions src/main/java/bwfdm/replaydh/workflow/Checksum.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
* Unless expressly otherwise stated, code from this project is licensed under the MIT license [https://opensource.org/licenses/MIT].
*
*
* Copyright (c) <2018> <Markus Gärtner, Volodymyr Kushnarenko, Florian Fritze, Sibylle Hermann and Uli Hahn>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
* THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package bwfdm.replaydh.workflow;
Expand All @@ -24,7 +24,7 @@
import java.util.Arrays;
import java.util.Objects;

import javax.xml.bind.DatatypeConverter;
import bwfdm.replaydh.utils.RDHUtils;

/**
* Models a checksum usable for consistency checking
Expand Down Expand Up @@ -73,7 +73,7 @@ public Checksum(String type, long size, String payload) {

this.type = type;
this.size = size;
this.payload = DatatypeConverter.parseHexBinary(payload);
this.payload = RDHUtils.parseHexBinary(payload);
checkArgument("Payload empty or too small", this.payload.length>=MIN_PAYLOAD_LENGTH);
}

Expand All @@ -97,7 +97,7 @@ public String toString() {
sb.append('#');
sb.append(Long.toHexString(size));
sb.append('#');
sb.append(DatatypeConverter.printHexBinary(getPayload()));
sb.append(RDHUtils.printHexBinary(getPayload()));

return sb.toString();
}
Expand Down Expand Up @@ -135,7 +135,7 @@ public static Checksum parse(String s) {

String type = splits[0];
long size = Long.parseUnsignedLong(splits[1], 16);
byte[] payload = DatatypeConverter.parseHexBinary(splits[2]);
byte[] payload = RDHUtils.parseHexBinary(splits[2]);

return new Checksum(type, size, payload);
}
Expand Down

0 comments on commit b901961

Please sign in to comment.