From 63f1caebaca86e04a2447cf66ce682d4d906f40b Mon Sep 17 00:00:00 2001
From: akwizgran <akwizgran@users.sourceforge.net>
Date: Sun, 10 Jul 2011 22:42:38 +0100
Subject: [PATCH] Iterators throw FormatRuntimeException if a FormatException
 occurs, or RuntimeException if an IO error occurs. Reduced visibility of impl
 classes.

---
 .../sf/briar/api/serial/FormatRuntimeException.java |  6 ++++++
 .../net/sf/briar/serial/ReaderFactoryImpl.java      |  2 +-
 components/net/sf/briar/serial/ReaderImpl.java      | 13 +++++++++++--
 .../net/sf/briar/serial/WriterFactoryImpl.java      |  2 +-
 components/net/sf/briar/serial/WriterImpl.java      |  4 ++--
 5 files changed, 21 insertions(+), 6 deletions(-)
 create mode 100644 api/net/sf/briar/api/serial/FormatRuntimeException.java

diff --git a/api/net/sf/briar/api/serial/FormatRuntimeException.java b/api/net/sf/briar/api/serial/FormatRuntimeException.java
new file mode 100644
index 0000000000..5b855bc03e
--- /dev/null
+++ b/api/net/sf/briar/api/serial/FormatRuntimeException.java
@@ -0,0 +1,6 @@
+package net.sf.briar.api.serial;
+
+public class FormatRuntimeException extends RuntimeException {
+
+	private static final long serialVersionUID = -6548900875808933998L;
+}
diff --git a/components/net/sf/briar/serial/ReaderFactoryImpl.java b/components/net/sf/briar/serial/ReaderFactoryImpl.java
index 2f52c03e2e..dd2a1a4da6 100644
--- a/components/net/sf/briar/serial/ReaderFactoryImpl.java
+++ b/components/net/sf/briar/serial/ReaderFactoryImpl.java
@@ -5,7 +5,7 @@ import java.io.InputStream;
 import net.sf.briar.api.serial.Reader;
 import net.sf.briar.api.serial.ReaderFactory;
 
-public class ReaderFactoryImpl implements ReaderFactory {
+class ReaderFactoryImpl implements ReaderFactory {
 
 	public Reader createReader(InputStream in) {
 		return new ReaderImpl(in);
diff --git a/components/net/sf/briar/serial/ReaderImpl.java b/components/net/sf/briar/serial/ReaderImpl.java
index cffaf557a4..fbbdba4bd0 100644
--- a/components/net/sf/briar/serial/ReaderImpl.java
+++ b/components/net/sf/briar/serial/ReaderImpl.java
@@ -11,10 +11,11 @@ import java.util.Map.Entry;
 import java.util.NoSuchElementException;
 
 import net.sf.briar.api.serial.FormatException;
+import net.sf.briar.api.serial.FormatRuntimeException;
 import net.sf.briar.api.serial.Reader;
 import net.sf.briar.api.serial.Tag;
 
-public class ReaderImpl implements Reader {
+class ReaderImpl implements Reader {
 
 	private static final int TOO_LARGE_TO_KEEP = 4096;
 
@@ -23,7 +24,7 @@ public class ReaderImpl implements Reader {
 	private byte next;
 	private byte[] stringBuffer = null;
 
-	public ReaderImpl(InputStream in) {
+	ReaderImpl(InputStream in) {
 		this.in = in;
 	}
 
@@ -398,6 +399,8 @@ public class ReaderImpl implements Reader {
 			remaining--;
 			try {
 				return readObject(e);
+			} catch(FormatException ex) {
+				throw new FormatRuntimeException();
 			} catch(IOException ex) {
 				throw new RuntimeException(ex);
 			}
@@ -434,6 +437,8 @@ public class ReaderImpl implements Reader {
 					hasNext = false;
 				}
 				return next;
+			} catch(FormatException ex) {
+				throw new FormatRuntimeException();
 			} catch(IOException ex) {
 				throw new RuntimeException(ex);
 			}
@@ -467,6 +472,8 @@ public class ReaderImpl implements Reader {
 			remaining--;
 			try {
 				return new MapEntry<K, V>(readObject(k), readObject(v));
+			} catch(FormatException ex) {
+				throw new FormatRuntimeException();
 			} catch(IOException ex) {
 				throw new RuntimeException(ex);
 			}
@@ -507,6 +514,8 @@ public class ReaderImpl implements Reader {
 					hasNext = false;
 				}
 				return next;
+			} catch(FormatException ex) {
+				throw new FormatRuntimeException();
 			} catch(IOException ex) {
 				throw new RuntimeException(ex);
 			}
diff --git a/components/net/sf/briar/serial/WriterFactoryImpl.java b/components/net/sf/briar/serial/WriterFactoryImpl.java
index de01ca18f4..63563fdf34 100644
--- a/components/net/sf/briar/serial/WriterFactoryImpl.java
+++ b/components/net/sf/briar/serial/WriterFactoryImpl.java
@@ -5,7 +5,7 @@ import java.io.OutputStream;
 import net.sf.briar.api.serial.Writer;
 import net.sf.briar.api.serial.WriterFactory;
 
-public class WriterFactoryImpl implements WriterFactory {
+class WriterFactoryImpl implements WriterFactory {
 
 	public Writer createWriter(OutputStream out) {
 		return new WriterImpl(out);
diff --git a/components/net/sf/briar/serial/WriterImpl.java b/components/net/sf/briar/serial/WriterImpl.java
index cb692846b0..aca49adc17 100644
--- a/components/net/sf/briar/serial/WriterImpl.java
+++ b/components/net/sf/briar/serial/WriterImpl.java
@@ -10,11 +10,11 @@ import net.sf.briar.api.serial.Raw;
 import net.sf.briar.api.serial.Tag;
 import net.sf.briar.api.serial.Writer;
 
-public class WriterImpl implements Writer {
+class WriterImpl implements Writer {
 
 	private final OutputStream out;
 
-	public WriterImpl(OutputStream out) {
+	WriterImpl(OutputStream out) {
 		this.out = out;
 	}
 
-- 
GitLab