Skip to content

Commit

Permalink
Fixed toString so it prints something more meaningful. [27678515]
Browse files Browse the repository at this point in the history
  • Loading branch information
SQUIDwarrior committed Apr 7, 2012
1 parent 2f09e1c commit fffab3e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
14 changes: 13 additions & 1 deletion src/main/java/edu/cmu/sv/arinc838/util/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ public class Converter {
public static byte[] hexToBytes(String hexString) {
return new HexBinaryAdapter().unmarshal(hexString);
}
}

/**
* Converts the byte array into a hexadecimal string representation. The
* output string will not include the common "0x" prefix.
*
* @param bytes
* The byte array to be converted
* @return The hexadecimal string representation
*/
public static String bytesToHex(byte[] bytes) {
return new HexBinaryAdapter().marshal(bytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import edu.cmu.sv.arinc838.dao.IntegrityDefinitionDao.IntegrityType;
import edu.cmu.sv.arinc838.dao.SoftwareDefinitionFileDao;
import edu.cmu.sv.arinc838.dao.SoftwareDescriptionDao;
import edu.cmu.sv.arinc838.util.Converter;

/**
* <p>
Expand Down Expand Up @@ -242,10 +243,10 @@ public byte[] validateFileFormatVersion(byte[] version) {
if (!Arrays.equals(version,
SoftwareDefinitionFileDao.DEFAULT_FILE_FORMAT_VERSION)) {
throw new IllegalArgumentException(
"File format version was set to "
+ version
+ ", expected "
+ SoftwareDefinitionFileDao.DEFAULT_FILE_FORMAT_VERSION);
"File format version was set to 0x"
+ Converter.bytesToHex(version)
+ ", expected 0x"
+ Converter.bytesToHex(SoftwareDefinitionFileDao.DEFAULT_FILE_FORMAT_VERSION));
}
return version;
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/edu/cmu/sv/arinc838/util/ConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ public void hexToBytes() {
assertEquals(Converter.hexToBytes("DEADBEEF"), new byte[] { (byte) 222,
(byte) 173, (byte) 190, (byte) 239 });
}

@Test
public void bytesToHex() {
assertEquals(Converter.bytesToHex(new byte[] { (byte) 222,
(byte) 173, (byte) 190, (byte) 239 }), "DEADBEEF");
}

}

0 comments on commit fffab3e

Please sign in to comment.