{
System.out.println("Target file is not valid: " + target);
System.exit(1);
}
final ByteTable table = new ByteTable(MAX_RANGES, 256);
final BufferedReader reader = new BufferedReader(new FileReader(f));
String line;
while ((line = reader.readLine()) != null)
{
if (line.length() > 0 && line.charAt(0) == '#')
{
continue;
}
if (line.trim().length() == 0)
{
continue;
}
final int separator = line.indexOf(';');
if (separator < 1)
{
continue;
}
int comment = line.indexOf('#');
if (comment == -1)
{
comment = line.length();
}
final String chars = line.substring(0, separator).trim();
final String classification = line.substring(separator + 1, comment).trim();
final int range = chars.indexOf("..");
if (range == -1)
{
final int idx = Integer.parseInt(chars, 16);
final int targetRange = idx >> 8;
table.setByte(targetRange, idx & 0xFF, classify (classification));
}
else
{
final int startRange = Integer.parseInt(chars.substring(0, range), 16);
final int endRange = Integer.parseInt(chars.substring(range + 2), 16);
for (int i = startRange; i < endRange; i++)
{
final int targetRange = i >> 8;
table.setByte(targetRange, i & 0xFF, classify (classification));
}
}
}
final FileOutputStream targetStream = new FileOutputStream(target);