use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.
the class Utils method getOffsets.
/**
* Gets the offsets of the string offsets.
*
* @param string the string
* @return the offsets
* @throws IOException the exception
*/
public static List<OffsetEntry> getOffsets(String string) throws IOException {
if (string.endsWith(Constants.OFF_EXTENSION)) {
string = FileUtils.getCleanOffsets(string);
}
string = string.toUpperCase();
List<OffsetEntry> offsets = new ArrayList<>();
for (String offsetString : string.split(Constants.OFFSET_STR_SEPARATOR)) {
OffsetEntry entry = new OffsetEntry();
String[] values = offsetString.split(Constants.OFFSET_CHAR_SEPARATOR);
entry.setStart(Integer.parseInt(values[0], Constants.HEX_RADIX));
if (values.length > 1) {
entry.setEnd(Integer.parseInt(values[1], Constants.HEX_RADIX));
if (values.length > 2) {
for (int i = 2; i < values.length; i++) {
entry.getEndChars().add(values[i]);
}
}
}
offsets.add(entry);
}
return offsets;
}
use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.
the class Utils method getHexOffsets.
/**
* Get the OffsetEntries of the string.
*
* @param entries the entries
* @return the hex offsets
*/
public static List<OffsetEntry> getHexOffsets(String entries) {
List<OffsetEntry> entryList = new ArrayList<>();
for (String entryStr : entries.replace(Constants.SPACE_STR, Constants.EMPTY).split(Constants.OFFSET_STR_SEPARATOR)) {
OffsetEntry entry = null;
if (entryStr.contains(Constants.OFFSET_CHAR_SEPARATOR)) {
// 00001-00003 type init-end (inclusives)
int[] numbers = hexStringListToIntList(entryStr.split(Constants.OFFSET_CHAR_SEPARATOR));
entry = new OffsetEntry(numbers[0], numbers[1], null);
} else {
if (entryStr.contains(Constants.OFFSET_LENGTH_SEPARATOR)) {
// 00001:00003 type init:length
int[] numbers = hexStringListToIntList(entryStr.split(Constants.OFFSET_LENGTH_SEPARATOR));
entry = new OffsetEntry(numbers[0], numbers[0] + numbers[1] - 1, null);
} else {
log("Invalid Offset entry!!!!! : " + entryStr);
}
}
if (entry != null) {
entryList.add(entry);
}
}
return entryList;
}
use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.
the class UtilsTest method toFileString.
@Test
public void toFileString() {
List<OffsetEntry> offEntries = new ArrayList<>();
offEntries.add(new OffsetEntry(0, 1, Arrays.asList("FF", "00")));
offEntries.add(new OffsetEntry(5, 10, Arrays.asList("01", "00")));
Assert.assertEquals("00000000-00000001-FF-00,00000005-0000000A-01-00", Utils.toFileString(offEntries));
}
use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.
the class UtilsTest method getHexOffsets.
@Test
public void getHexOffsets() {
String entries = "0-1,5:6";
List<OffsetEntry> offEntries = new ArrayList<>();
offEntries.add(new OffsetEntry(0, 1, null));
offEntries.add(new OffsetEntry(5, 10, null));
Assert.assertEquals(offEntries, Utils.getHexOffsets(entries));
}
use of com.wave.hextractor.pojo.OffsetEntry in project hextractor by sewave.
the class HexTableTest method toAscii2.
@Test
public void toAscii2() {
HexTable table = new HexTable(LINES);
byte[] data = new byte[] { 0, 1, 2, 3, 4 };
OffsetEntry entry = new OffsetEntry(0, 4, Collections.singletonList("FF"));
String ascii = "@00000000-00000004-FF\n" + ";00000000{abc{ab}~04~}#011#005\n" + "abc{ab}~04~#005\n" + "|5\n";
Assert.assertEquals(ascii, table.toAscii(data, entry, true));
Assert.assertEquals(ascii, table.toAscii(data, entry, false));
}
Aggregations