try { outStream = new FileOutputStream(file); OpenmrsUtil.copyFile(input, outStream);
private void copyInputStreamToFile(InputStream inputStream, File file) { try (FileOutputStream outputStream = new FileOutputStream(file)) { OpenmrsUtil.copyFile(inputStream, outputStream); } catch (IOException e) { throw new ModuleException(messageSourceService.getMessage("Module.error.cannotCreateFile"), e); } finally { try { inputStream.close(); } catch (Exception e) { /* pass */} } }
inputStream = new FileInputStream(fromPath); outputStream = new FileOutputStream(toPath); OpenmrsUtil.copyFile(inputStream, outputStream);
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("In service method for module servlet: " + request.getPathInfo()); File f = getFile(request); if (f == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } response.setDateHeader("Last-Modified", f.lastModified()); response.setContentLength(Long.valueOf(f.length()).intValue()); String mimeType = getServletContext().getMimeType(f.getName()); response.setContentType(mimeType); FileInputStream is = new FileInputStream(f); try { OpenmrsUtil.copyFile(is, response.getOutputStream()); } finally { OpenmrsUtil.closeStream(is); } }
OpenmrsUtil.copyFile(in, out); output = out.toString(StandardCharsets.UTF_8.name());
copyFile(in, out); return new ByteArrayInputStream(out.toByteArray());
OpenmrsUtil.copyFile(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream( new File(moduleRepository, fileName)))); } else {
try { imageFileInputStream = new FileInputStream(file); OpenmrsUtil.copyFile(imageFileInputStream, httpResponse.getOutputStream());
try { outputStream = new FileOutputStream(file); OpenmrsUtil.copyFile(inputStream, outputStream);
OutputStream out = new BufferedOutputStream(fileOut); try { OpenmrsUtil.copyFile(in, out);
OpenmrsUtil.copyFile(stream, outStream);
/** * @throws IOException * @see OpenmrsUtil#copyFile(InputStream, OutputStream) */ @Test public void copyFile_shouldNotCopyTheOutputstreamIfInputstreamIsNull() throws IOException { InputStream input = null; ByteArrayOutputStream output = spy(new ByteArrayOutputStream()); OpenmrsUtil.copyFile(input, output); assertNull(input); assertNotNull(output); verify(output, times(1)).close(); }
InputStream sqlFileInputStream = fileOpener.getResourceAsStream(sqlFile); OutputStream outputStream = new FileOutputStream(tmpOutputFile); OpenmrsUtil.copyFile(sqlFileInputStream, outputStream);
/** * @throws IOException * @see OpenmrsUtil#copyFile(InputStream, OutputStream) */ @Test public void copyFile_shouldCopyInputstreamToOutputstreamAndCloseTheOutputstream() throws IOException { String exampleInputStreamString = "ExampleInputStream"; ByteArrayInputStream expectedByteArrayInputStream = new ByteArrayInputStream(exampleInputStreamString.getBytes()); ByteArrayOutputStream output = spy(new ByteArrayOutputStream()); OpenmrsUtil.copyFile(expectedByteArrayInputStream, output); expectedByteArrayInputStream.reset(); ByteArrayInputStream byteArrayInputStreamFromOutputStream = new ByteArrayInputStream(output.toByteArray()); assertTrue(IOUtils.contentEquals(expectedByteArrayInputStream, byteArrayInputStreamFromOutputStream)); verify(output, times(1)).close(); }
in = new FileInputStream(module.getFile()); out = new FileOutputStream(tmpModuleJar); OpenmrsUtil.copyFile(in, out);
} else if (InputStream.class.isAssignableFrom(data.getClass())) { try { OpenmrsUtil.copyFile((InputStream) data, fout);
/** * @throws IOException * @see OpenmrsUtil#copyFile(InputStream, OutputStream) */ @Test public void copyFile_shouldNotCopyTheOutputstreamWhenOutputstreamIsNull() throws IOException { String exampleInputStreamString = "ExampleInputStream"; ByteArrayInputStream input = new ByteArrayInputStream(exampleInputStreamString.getBytes()); OutputStream output = null; OpenmrsUtil.copyFile(input, output); assertNull(output); assertNotNull(input); }
/** * @see ComplexObsHandler#saveObs(Obs) */ @Override public Obs saveObs(Obs obs) throws APIException { try { // Write the File to the File System String fileName = obs.getComplexData().getTitle(); InputStream in = (InputStream) obs.getComplexData().getData(); File outfile = getOutputFileToWrite(obs); OutputStream out = new FileOutputStream(outfile, false); OpenmrsUtil.copyFile(in, out); // Store the filename in the Obs obs.setComplexData(null); obs.setValueComplex(fileName + "|" + outfile.getName()); // close the stream out.close(); } catch (Exception e) { throw new APIException("Obs.error.writing.binary.data.complex", null, e); } return obs; }
OpenmrsUtil.copyFile(inStream, outStream);
/** * @see org.openmrs.obs.ComplexObsHandler#saveObs(org.openmrs.Obs) */ @Override public Obs saveObs(Obs obs) throws APIException { try { // Write the File to the File System String fileName = obs.getComplexData().getTitle(); File outfile = getOutputFileToWrite(obs); OutputStream out = new FileOutputStream(outfile, false); FileInputStream mediaStream = (FileInputStream) obs.getComplexData().getData(); OpenmrsUtil.copyFile(mediaStream, out); // Store the filename in the Obs obs.setComplexData(null); obs.setValueComplex(fileName + "|" + outfile.getName()); // close the stream out.close(); } catch (IOException ioe) { throw new APIException("Obs.error.trying.write.complex", null, ioe); } return obs; }