/** * Get a local copy of a file. If the dataId matches any of the files found from local filebroker * paths (given in constructor of this class), then it is symlinked or copied locally. Otherwise * the file pointed by the dataId is downloaded. * * @throws JMSException * @throws ChecksumException * @see fi.csc.microarray.filebroker.FileBrokerClient#getFile(File, URL) */ @Override public void getFile(UUID sessionId, String dataId, File destFile) throws IOException, FileBrokerException, ChecksumException { InputStream inStream = download(sessionId, dataId); IOUtils.copy(inStream, destFile); }
private void convertToLocalTempDataBean(DataBean bean) throws IOException { try { // copy contents to new file File newFile = this.createNewRepositoryFile(bean.getName()); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(newFile)); ChecksumInputStream inputStream = getContentStream(bean, DataNotAvailableHandling.EXCEPTION_ON_NA); BufferedInputStream in = new BufferedInputStream(inputStream); try { IOUtils.copy(in, out); setOrVerifyChecksum(bean, inputStream.verifyChecksums()); } finally { IOUtils.closeIfPossible(in); IOUtils.closeIfPossible(out); } // update url, type and handler in the bean URL newURL = newFile.toURI().toURL(); addContentLocationForDataBean(bean, StorageMethod.LOCAL_TEMP, newURL); } catch (ChecksumException | ContentLengthException e) { // corrupted data throw new IOException(); } }
private String getSourceCode(String sourceCodeFileName) throws ZipException, IOException { ZipFile zipFile = null; InputStream sourceCodeInputStream = null; StringWriter stringWriter = null; try { zipFile = new ZipFile(sessionFile); sourceCodeInputStream = zipFile.getInputStream(zipFile.getEntry(sourceCodeFileName)); stringWriter = new StringWriter(); IOUtils.copy(sourceCodeInputStream, new WriterOutputStream(stringWriter)); stringWriter.flush(); } finally { IOUtils.closeIfPossible(sourceCodeInputStream); IOUtils.closeIfPossible(stringWriter); if (zipFile != null) { zipFile.close(); } } return stringWriter.toString(); }