Commit 903f0882 authored by yorn's avatar yorn

Solve various reading problems

- Fixed leaking of signature bit to higher bits (negative signed bytes
had unpredictable results)
- Preprocessing didn’t clear clear previous line, causing shorter lines
to be mangled
parent d66e8313
package no.uninett.yorn.giraph.format.io;
import java.io.IOException;
import java.nio.charset.Charset;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
......@@ -26,7 +26,6 @@ public class NetflowCSVEdgeInputFormat extends
private static final long MASK_TIME = 0x0000FFFFFFFFFFFFL;
private static final Charset ASCII = Charset.forName("ASCII");
private static final DateFormat DATE_FORMAT = new SimpleDateFormat(
"YYYY-MM-dd hh:mm:ss.SSS");
......@@ -36,7 +35,7 @@ public class NetflowCSVEdgeInputFormat extends
for (int i = 0; i < 4; i++) {
octets[i] = (byte) Integer.parseInt(octetStrings[i]);
}
return octets[0] << 24 | octets[1] << 16 | octets[2] << 8 | octets[3];
return octets[0] << 24 | octets[1] << 16 & 0xFF0000 | octets[2] << 8 & 0xFF00 | octets[3] & 0xFF;
}
public class NetflowEdgeReader extends
......@@ -50,7 +49,8 @@ public class NetflowCSVEdgeInputFormat extends
/** {@inheritDoc} */
@Override
protected String[] preprocessLine(Text line) throws IOException {
return new String(line.getBytes(), ASCII).split(",");
String[] result = line.toString().split(",");
return result;
}
/** {@inheritDoc} */
......@@ -59,7 +59,7 @@ public class NetflowCSVEdgeInputFormat extends
throws IOException {
int port = Integer.parseInt(line[PORT]);
/* We switch around source and destination IP! */
return new LongWritable(port << 32 | ipToInt(line[SOURCE_IP]));
return new LongWritable((long)port << 32 | ( (long)ipToInt(line[SOURCE_IP]) & 0xFFFFFFFFL) );
}
/** {@inheritDoc} */
......@@ -68,16 +68,16 @@ public class NetflowCSVEdgeInputFormat extends
throws IOException {
int port = Integer.parseInt(line[PORT]);
/* We switch around source and destination IP! */
return new LongWritable(port << 32 | ipToInt(line[DEST_IP]));
return new LongWritable((long)port << 32 | ( (long)ipToInt(line[DEST_IP]) & 0xFFFFFFFFL) );
}
/** {@inheritDoc} */
@Override
protected LongWritable getValue(String[] line) throws IOException {
try {
Date terminationDate = DATE_FORMAT.parse(line[DATE]);
return new LongWritable(terminationDate.getTime() & MASK_TIME);
} catch (Exception e) {
Date date = DATE_FORMAT.parse(line[DATE]);
return new LongWritable(date.getTime() & MASK_TIME);
} catch (ParseException e) {
throw new IOException(e);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment