@Test public void wrapsOutputExceptionsWithAHelpfulMessage() { final EOFException connectionException = new EOFException(); BinaryRepresentation r = new BinaryRepresentation("foo/bar", new ByteArrayInputStream(DSL.getBytes("foobar", StandardCharset.UTF_8))); OutputStream out = new OutputStream() { @Override public void write(int b) throws IOException { throw connectionException; } }; Throwable err = null; try { r.write(out); } catch (Exception e) { err = e; } assertNotNull(err); assertEquals("Error writing representation. This is probably because the connection to the remote host was closed.", err.getMessage()); assertTrue(err.getCause() == connectionException); err.printStackTrace(); }
@Override public void write(OutputStream out) { try { byte[] buffer = new byte[1024]; for(int x=data.read(buffer);x!=-1;x=data.read(buffer)){ try{ out.write(buffer, 0, x); }catch(Exception err){ throw new RuntimeException("Error writing representation. This is probably because the connection to the remote host was closed.", err); } } data.close(); } catch (IOException e) { throw new RuntimeException(e); } }
BinaryRepresentation implements Representation { @Override public void write(OutputStream out) { try { byte[] buffer = new byte[1024]; for(int x=data.read(buffer);x!=-1;x=data.read(buffer)){ try{ out.write(buffer, 0, x); }catch(Exception err){ throw new RuntimeException("Error writing representation. This is probably because the connection to the remote host was closed.", err); } } data.close(); } catch (IOException e) { throw new RuntimeException(e); } } }
BinaryRepresentation implements Representation { @Override public void write(OutputStream out) { try { byte[] buffer = new byte[1024]; for(int x=data.read(buffer);x!=-1;x=data.read(buffer)){ try{ out.write(buffer, 0, x); }catch(Exception err){ throw new RuntimeException("Error writing representation. This is probably because the connection to the remote host was closed.", err); } } data.close(); } catch (IOException e) { throw new RuntimeException(e); } } BinaryRepresentation(String contentType, InputStream data); }
BinaryRepresentation implements Representation { @Override public void write(OutputStream out) { try { byte[] buffer = new byte[1024]; for(int x=data.read(buffer);x!=-1;x=data.read(buffer)){ try{ out.write(buffer, 0, x); }catch(Exception err){ throw new RuntimeException("Error writing representation. This is probably because the connection to the remote host was closed.", err); } } data.close(); } catch (IOException e) { throw new RuntimeException(e); } } BinaryRepresentation(String contentType, InputStream data); @Override String contentType(); @Override void write(OutputStream out); }
BinaryRepresentation implements Representation { @Override public void write(OutputStream out) { try { byte[] buffer = new byte[1024]; for(int x=data.read(buffer);x!=-1;x=data.read(buffer)){ try{ out.write(buffer, 0, x); }catch(Exception err){ throw new RuntimeException("Error writing representation. This is probably because the connection to the remote host was closed.", err); } } data.close(); } catch (IOException e) { throw new RuntimeException(e); } } BinaryRepresentation(String contentType, InputStream data); @Override String contentType(); @Override void write(OutputStream out);  }