diff options
author | Keith Packard <keithp@keithp.com> | 2017-05-28 14:00:15 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2017-05-28 14:04:21 -0700 |
commit | da914cd72411af8c36af05b13c11b9093c8a378c (patch) | |
tree | 9443f90fbf21315b609631c300bfb4acb3ac23da /altoslib/AltosLib.java | |
parent | 9e1295ff74d03f940fc68e6795bf30687162a440 (diff) |
altoslib: Create data file open helper in AltosLib
Use InputStream everywhere, instead of Reader.
Create private string input stream as java one is deprecated.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosLib.java')
-rw-r--r-- | altoslib/AltosLib.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/altoslib/AltosLib.java b/altoslib/AltosLib.java index 355c7a27..6c1729df 100644 --- a/altoslib/AltosLib.java +++ b/altoslib/AltosLib.java @@ -588,4 +588,28 @@ public class AltosLib { public static String igniter_name(int i) { return String.format("Ignitor %c", 'A' + i); } + + public static AltosRecordSet record_set(File file) throws FileNotFoundException, IOException { + FileInputStream in; + in = new FileInputStream(file); + if (file.getName().endsWith("telem")) { + return new AltosTelemetryFile(in); + } else if (file.getName().endsWith("eeprom")) { + return new AltosEepromFile(in); + } else { + String name = file.getName(); + int dot = name.lastIndexOf('.'); + String extension; + + if (dot == -1) + throw new IOException(String.format("%s (Missing extension)", file.toString())); + else { + extension = name.substring(dot); + throw new IOException(String.format("%s (Invalid extension '%s')", + file.toString(), + extension)); + } + } + } + } |