+ return true;
+ }
+
+ private void read(InputStream stream) throws IOException {
+ BufferedInputStream bis = new BufferedInputStream(stream);
+
+ bis.mark(1);
+ int c = bis.read();
+ bis.reset();
+
+ if (c == '{') {
+ if (!read_config(bis))
+ throw new IOException("failed to read config");
+ if (!read_data(bis))
+ throw new IOException("failed to read data");
+ } else {
+ if (!read_old_config(bis))
+ throw new IOException("failed to read old config");
+ if (!read_old_data(bis))
+ throw new IOException("failed to read old data");
+ }
+ }
+
+ /*
+ * Public APIs for I/O
+ */
+ public void write(Writer w) throws IOException {
+ write_config(w);
+ write_data(w);
+ }
+
+ public String toString() {
+ try {
+ Writer w = new StringWriter();
+
+ write(w);
+ return w.toString();
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public void print() throws IOException {
+ System.out.printf("%s", toString());
+ }
+
+ /*
+ * Constructors
+ */
+ public AltosEeprom(InputStream stream) throws IOException {
+ read(stream);
+ }
+
+ public AltosEeprom(String s) throws IOException {
+ read(new AltosStringInputStream(s));
+ }
+
+ public AltosEeprom(AltosJson config, ArrayList<Byte> data) {
+ this.config = config;
+ this.data = data;
+ }
+
+ public AltosEeprom(AltosConfigData config_data, ArrayList<Byte> data) {
+ this.config = new AltosJson(config_data);
+ this.data = data;
+ }
+
+ public AltosEeprom() {