From 9c86937e5287621cdf80a7f2d0e2619d175874c5 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 13 Mar 2017 20:47:02 -0400 Subject: tidy --- dslog/CsvWriter.java | 13 ++++--------- dslog/Main.java | 15 ++++++++------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/dslog/CsvWriter.java b/dslog/CsvWriter.java index 21e31e1..3506733 100644 --- a/dslog/CsvWriter.java +++ b/dslog/CsvWriter.java @@ -1,9 +1,9 @@ package dslog; -import java.io.EOFException; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; +import java.util.Iterator; class CsvWriter { private static String line3(DslogReader.Entry e) { @@ -46,16 +46,11 @@ class CsvWriter { e.pdpVoltage+","+ e.pdpTemperature; } - public static void Dslog2CSV(DslogReader in, OutputStream _out) throws IOException { + public static void Dslog2CSV(Iterator in, OutputStream _out) throws IOException { PrintStream out = new PrintStream(_out); out.println("time,tripTime,lost (packets),voltage (V),cpu (%),robot disable,robot auto,robot tele,ds disable,ds auto,ds tele,watchdog,brownout,CAN (%),signal (dB),bandwidth (Mb),PDP ID,PDP pad,PDP-0,PDP-1,PDP-2,PDP-3,PDP-4,PDP-5,PDP-6,PDP-7,PDP-8,PDP-9,PDP-10,PDP-11,PDP-12,PDP-13,PDP-14,PDP-15,PDP Resistance,PDP Voltage,PDP Temperature"); - for (;;) { - try { - out.println(line3(in.readEntry())); - } catch (EOFException e) { - break; - } + while (in.hasNext()) { + out.println(line3(in.next())); } - in.close(); } } diff --git a/dslog/Main.java b/dslog/Main.java index 5ea1a64..0d35e8b 100644 --- a/dslog/Main.java +++ b/dslog/Main.java @@ -10,22 +10,23 @@ import java.util.Map; import java.util.TreeMap; class Main { - public static void dslog2csv(String[] args) throws IOException { - for (String filename : args) { - System.out.println("Filename: "+filename); - DslogReader file = new DslogReader(Files.newInputStream(Paths.get(filename))); + public static void dslog2csv(String filename) throws IOException { + try (DslogReader file = new DslogReader(Files.newInputStream(Paths.get(filename)))) { System.out.println("Format Version: "+file.version()); System.out.println("Start Time: "+file.startTime()); CsvWriter.Dslog2CSV(file, System.out); } } + public static void ls(String dirname) throws IOException { + Logdir.opendir(dirname).forEach((k,v)->{ + System.out.println(v); + }); + } public static void main(String[] args) throws IOException { for (String dirname : args) { - Logdir.opendir(dirname).forEach((k,v)->{ - System.out.println(v); - }); + ls(dirname); } } } -- cgit v1.2.3