Iterators throw FormatRuntimeException if a FormatException occurs, or RuntimeException if an IO error occurs. Reduced visibility of impl classes.

This commit is contained in:
akwizgran
2011-07-10 22:42:38 +01:00
parent 0f4ffe9fbc
commit 63f1caebac
5 changed files with 21 additions and 6 deletions

View File

@@ -0,0 +1,6 @@
package net.sf.briar.api.serial;
public class FormatRuntimeException extends RuntimeException {
private static final long serialVersionUID = -6548900875808933998L;
}

View File

@@ -5,7 +5,7 @@ import java.io.InputStream;
import net.sf.briar.api.serial.Reader; import net.sf.briar.api.serial.Reader;
import net.sf.briar.api.serial.ReaderFactory; import net.sf.briar.api.serial.ReaderFactory;
public class ReaderFactoryImpl implements ReaderFactory { class ReaderFactoryImpl implements ReaderFactory {
public Reader createReader(InputStream in) { public Reader createReader(InputStream in) {
return new ReaderImpl(in); return new ReaderImpl(in);

View File

@@ -11,10 +11,11 @@ import java.util.Map.Entry;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import net.sf.briar.api.serial.FormatException; 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.Reader;
import net.sf.briar.api.serial.Tag; 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; private static final int TOO_LARGE_TO_KEEP = 4096;
@@ -23,7 +24,7 @@ public class ReaderImpl implements Reader {
private byte next; private byte next;
private byte[] stringBuffer = null; private byte[] stringBuffer = null;
public ReaderImpl(InputStream in) { ReaderImpl(InputStream in) {
this.in = in; this.in = in;
} }
@@ -398,6 +399,8 @@ public class ReaderImpl implements Reader {
remaining--; remaining--;
try { try {
return readObject(e); return readObject(e);
} catch(FormatException ex) {
throw new FormatRuntimeException();
} catch(IOException ex) { } catch(IOException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@@ -434,6 +437,8 @@ public class ReaderImpl implements Reader {
hasNext = false; hasNext = false;
} }
return next; return next;
} catch(FormatException ex) {
throw new FormatRuntimeException();
} catch(IOException ex) { } catch(IOException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@@ -467,6 +472,8 @@ public class ReaderImpl implements Reader {
remaining--; remaining--;
try { try {
return new MapEntry<K, V>(readObject(k), readObject(v)); return new MapEntry<K, V>(readObject(k), readObject(v));
} catch(FormatException ex) {
throw new FormatRuntimeException();
} catch(IOException ex) { } catch(IOException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@@ -507,6 +514,8 @@ public class ReaderImpl implements Reader {
hasNext = false; hasNext = false;
} }
return next; return next;
} catch(FormatException ex) {
throw new FormatRuntimeException();
} catch(IOException ex) { } catch(IOException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }

View File

@@ -5,7 +5,7 @@ import java.io.OutputStream;
import net.sf.briar.api.serial.Writer; import net.sf.briar.api.serial.Writer;
import net.sf.briar.api.serial.WriterFactory; import net.sf.briar.api.serial.WriterFactory;
public class WriterFactoryImpl implements WriterFactory { class WriterFactoryImpl implements WriterFactory {
public Writer createWriter(OutputStream out) { public Writer createWriter(OutputStream out) {
return new WriterImpl(out); return new WriterImpl(out);

View File

@@ -10,11 +10,11 @@ import net.sf.briar.api.serial.Raw;
import net.sf.briar.api.serial.Tag; import net.sf.briar.api.serial.Tag;
import net.sf.briar.api.serial.Writer; import net.sf.briar.api.serial.Writer;
public class WriterImpl implements Writer { class WriterImpl implements Writer {
private final OutputStream out; private final OutputStream out;
public WriterImpl(OutputStream out) { WriterImpl(OutputStream out) {
this.out = out; this.out = out;
} }