@Override public void write(Object value, OutputStream output, Operation operation) throws IOException, ServiceException { InputStream input = null; try { input = ((RepositoryItem) value).getContents(); if (null != input) { IOUtils.copy(input, output); } else { throw new HttpErrorCodeException(404, "Repository item had no content"); } } catch (IOException e) { throw new ServiceException("Failed to encode the repository item onto the output", e); } finally { IOUtils.closeQuietly(input); output.flush(); } } }
@Override public void write(Object value, OutputStream output, Operation operation) throws IOException, ServiceException { InputStream input = null; try { input = ((RepositoryItem) value).getContents(); if (null != input) { IOUtils.copy(input, output); } else { throw new HttpErrorCodeException(404, "Repository item had no content"); } } catch (IOException e) { throw new ServiceException("Failed to encode the repository item onto the output", e); } finally { IOUtils.closeQuietly(input); output.flush(); } }
@Test public void testGetRepositoryItem() throws IOException { RepositoryItem item = store.getRepositoryItem("foo"); assertNull(item); item = store.getRepositoryItem("urn:uuid:19887a8a-f6b0-4a63-ae56-7fba0e17801f"); assertNotNull(item); assertEquals("application/xml", item.getMime()); String contents = IOUtils.toString(item.getContents(), "UTF-8"); String expected = "This is a random comment that will show up only when fetching the repository item"; assertTrue(contents.contains(expected)); } }