List of usage examples for org.apache.commons.io FileUtils readFileToByteArray
public static byte[] readFileToByteArray(File file) throws IOException
From source file:com.cc.zk.common.ZkClient.java
public void makePath(String path, File file, boolean failOnExists, boolean retryOnConnLoss) throws IOException, KeeperException, InterruptedException { makePath(path, FileUtils.readFileToByteArray(file), CreateMode.PERSISTENT, null, failOnExists, retryOnConnLoss);/*from w ww. ja va 2 s.c o m*/ }
From source file:com.falkonry.TestAddDataStream.java
/** * Should add wide data to datastream in stream CSV format * @throws Exception//from w w w . ja v a 2 s. co m */ @Test public void addWideDataCsvStream() throws Exception { Datastream ds = new Datastream(); ds.setName("Test-DS4-" + Math.random()); TimeObject time = new TimeObject(); time.setIdentifier("time"); time.setFormat("millis"); time.setZone("GMT"); Datasource dataSource = new Datasource(); dataSource.setType("STANDALONE"); List<Input> inputList = new ArrayList<Input>(); ; Input input1 = new Input(); input1.setName("signal1"); EventType eventType1 = new EventType(); eventType1.setType("Samples"); input1.setEventType(eventType1); ValueType valueType1 = new ValueType(); valueType1.setType("Numeric"); input1.setValueType(valueType1); inputList.add(input1); Input input2 = new Input(); input2.setName("signal2"); EventType eventType2 = new EventType(); eventType2.setType("Samples"); input2.setEventType(eventType2); ValueType valueType2 = new ValueType(); valueType2.setType("Numeric"); input2.setValueType(valueType2); inputList.add(input2); Input input3 = new Input(); input3.setName("signal3"); EventType eventType3 = new EventType(); eventType3.setType("Samples"); input3.setEventType(eventType3); ValueType valueType3 = new ValueType(); valueType3.setType("Numeric"); input3.setValueType(valueType3); inputList.add(input3); Input input4 = new Input(); input4.setName("signal4"); EventType eventType4 = new EventType(); eventType4.setType("Samples"); input4.setEventType(eventType4); ValueType valueType4 = new ValueType(); valueType4.setType("Numeric"); input4.setValueType(valueType4); inputList.add(input4); Input input5 = new Input(); input5.setName("signal5"); EventType eventType5 = new EventType(); eventType5.setType("Samples"); input5.setEventType(eventType5); ValueType valueType5 = new ValueType(); valueType5.setType("Numeric"); input5.setValueType(valueType5); inputList.add(input5); ds.setInputList(inputList); Field field = new Field(); field.setTime(time); field.setEntityIdentifier("thing"); ds.setDatasource(dataSource); ds.setField(field); Datastream datastream = falkonry.createDatastream(ds); datastreams.add(datastream); Map<String, String> options = new HashMap<String, String>(); File file = new File("res/data_wide.csv"); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(FileUtils.readFileToByteArray(file)); InputStatus inputStatus = falkonry.addInputStream(datastream.getId(), byteArrayInputStream, options); Assert.assertEquals(inputStatus.getAction(), "ADD_DATA_DATASTREAM"); Assert.assertEquals(inputStatus.getStatus(), "PENDING"); Datastream datastream1 = falkonry.getDatastream(datastream.getId()); Assert.assertEquals(datastream1.getId(), datastream.getId()); Assert.assertEquals(datastream1.getName(), datastream.getName()); Assert.assertEquals(datastream1.getInputList().size(), datastream.getInputList().size()); }
From source file:com.t3.model.AssetManager.java
/** * Create an asset from a file./* w w w. j a v a 2s.c o m*/ * * @param file * File to use for asset * @return Asset associated with the file * @throws IOException */ public static Asset createAsset(URL url) throws IOException { // Create a temporary file from the downloaded URL File newFile = File.createTempFile("remote", null, null); try { FileUtils.copyURLToFile(url, newFile); if (!newFile.exists() || newFile.length() < 20) return null; Asset temp = new Asset(FileUtil.getNameWithoutExtension(url), FileUtils.readFileToByteArray(newFile)); return temp; } finally { newFile.delete(); } }
From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.Mp3Db.java
public Pair<String, byte[]> getMp3Zip(List<Track> tracks, String nameOfZip) { Pair<String, byte[]> ret = new Pair<String, byte[]>(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); ZipWriteFileSystem zfs = new ZipWriteFileSystem(bout); for (Track track : tracks) { File f = track.getMp3Path(); try {//from w w w .j a v a 2 s.c o m byte[] data = FileUtils.readFileToByteArray(f); Title title = track.getTitle(); Composer comp = title.getComposer(); String pname = comp.getNameOnFs() + "/" + track.getTitle().getNameOnFs() + "/" + track.getNameOnFs(); zfs.writeBinaryFile(pname, data, false); } catch (IOException ex) { GLog.warn(GWikiLogCategory.Wiki, "RogMp3; Error zipping file: " + f.getAbsolutePath() + "; " + ex.getMessage(), new LogExceptionAttribute(ex)); } } zfs.close(); ret.setFirst(nameOfZip); ret.setSecond(bout.toByteArray()); return ret; }
From source file:gov.nih.nci.nbia.wadosupport.WADOSupportDAOImpl.java
@Transactional(propagation = Propagation.REQUIRED) public WADOSupportDTO getThumbnailDTO(String series, String image, String user) { WADOSupportDTO returnValue = new WADOSupportDTO(); System.out.println("series-" + series + " image-" + image); try {//from w ww . j a v a2 s. c om List<Object[]> images = this.getHibernateTemplate().getSessionFactory().getCurrentSession() .createSQLQuery(WADO_SINGLE_QUERY).setParameter("series", series).setParameter("image", image) .list(); if (images.size() == 0) { log.info("image not found"); return null; //nothing to do } List<SiteData> authorizedSites; UserObject uo = userTable.get(user); if (uo != null) { authorizedSites = uo.getAuthorizedSites(); if (authorizedSites == null) { AuthorizationManager manager = new AuthorizationManager(user); authorizedSites = manager.getAuthorizedSites(); uo.setAuthorizedSites(authorizedSites); } } else { AuthorizationManager manager = new AuthorizationManager(user); authorizedSites = manager.getAuthorizedSites(); uo = new UserObject(); uo.setAuthorizedSites(authorizedSites); userTable.put(user, uo); } returnValue.setCollection((String) images.get(0)[0]); returnValue.setSite((String) images.get(0)[1]); boolean isAuthorized = false; for (SiteData siteData : authorizedSites) { if (siteData.getCollection().equals(returnValue.getCollection())) { if (siteData.getSiteName().equals(returnValue.getSite())) { isAuthorized = true; break; } } } if (!isAuthorized) { System.out.println("User: " + user + " not authorized"); return null; //not authorized } String filePath = (String) images.get(0)[2]; System.out.println("Image found:" + filePath); String mircThumbnailFilePath = filePath.substring(0, filePath.lastIndexOf(".dcm")) + "_base.jpeg"; //this isn't necessarily the thumbanil string //512, 512, and -1 can be configured in CTP's config.xml String ctpThumbnailFilePath = mircThumbnailFilePath.substring(0, mircThumbnailFilePath.indexOf("_base")) + ".dcm[512;512;-1].jpeg"; //this isn't necessarily the thumbanil string //512, 512, and -1 can be configured in CTP's config.xml String ctpNewThumbnailFilePath = mircThumbnailFilePath.substring(0, mircThumbnailFilePath.indexOf("_base")) + ".dcm[512;512;-1][0].jpeg"; File mircThumbnailFile = new File(mircThumbnailFilePath); File ctpThumbnailFile = new File(ctpThumbnailFilePath); File ctpNewThumbnailFile = new File(ctpNewThumbnailFilePath); File imageFile = new File(filePath); if (mircThumbnailFile.exists()) { returnValue.setImage(FileUtils.readFileToByteArray(mircThumbnailFile)); return returnValue; } else if (ctpThumbnailFile.exists()) { returnValue.setImage(FileUtils.readFileToByteArray(ctpThumbnailFile)); return returnValue; } else { returnValue.setImage(FileUtils.readFileToByteArray(ctpNewThumbnailFile)); return returnValue; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:com.netsteadfast.greenstep.util.UploadSupportUtils.java
public static byte[] getDataBytes(String uploadOid) throws ServiceException, IOException, Exception { if (StringUtils.isBlank(uploadOid)) { throw new Exception("parameter is blank!"); }//from w w w. jav a 2 s . c o m byte datas[] = null; SysUploadVO uploadObj = findUpload(uploadOid); datas = uploadObj.getContent(); if (YesNo.YES.equals(uploadObj.getIsFile())) { String uploadDir = getUploadFileDir(uploadObj.getSystem(), uploadObj.getSubDir(), uploadObj.getType()); File file = new File(uploadDir + "/" + uploadObj.getFileName()); datas = FileUtils.readFileToByteArray(file); file = null; } return datas; }
From source file:com.cc.zk.common.ZkClient.java
public void makePath(String path, File file, boolean retryOnConnLoss) throws IOException, KeeperException, InterruptedException { makePath(path, FileUtils.readFileToByteArray(file), retryOnConnLoss); }
From source file:com.bluexml.side.deployer.alfresco.directcopy.AlfrescoAmpHotDeployer.java
private void uploadFile(File model, String modelRepoName, String storepath, NamedValue[] props, ContentFormat format) throws IOException { Store store = new Store(Constants.WORKSPACE_STORE, "SpacesStore"); ParentReference parentReference = new ParentReference(store, null, storepath, Constants.ASSOC_CONTAINS, Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, modelRepoName)); // get the node String uuid = null;//from w w w .j av a 2 s. c o m // model exists ? String modelPath = storepath + "/cm:" + modelRepoName; Reference r = new Reference(store, null, modelPath); System.out.println("search for :" + modelPath); try { Node[] n = WebServiceFactory.getRepositoryService() .get(new Predicate(new Reference[] { r }, store, null)); if (n.length > 0) { // node exist do update instead of create uuid = n[0].getReference().getUuid(); System.out.println("Update model content in repository"); } } catch (Exception e) { e.printStackTrace(); // node do not exists System.out.println("Create model in repository"); CMLCreate create = new CMLCreate(null, parentReference, null, null, null, "{http://www.alfresco.org/model/content/1.0}content", props); CML cml = new CML(); cml.setCreate(new CMLCreate[] { create }); UpdateResult[] results = WebServiceFactory.getRepositoryService().update(cml); uuid = results[0].getDestination().getUuid(); } // set node content // read xml file byte[] bytes = FileUtils.readFileToByteArray(model); // set content Content content = WebServiceFactory.getContentService().write(new Reference(store, uuid, null), Constants.PROP_CONTENT, bytes, format); System.out.println("model content updated " + content); }
From source file:be.fedict.eid.idp.admin.webapp.bean.ConfigBean.java
@Override @Begin(join = true)//from w w w. ja v a 2s. c o m public void uploadListener(UploadEvent event) throws IOException { UploadItem item = event.getUploadItem(); this.log.debug(item.getContentType()); this.log.debug(item.getFileSize()); this.log.debug(item.getFileName()); if (null == item.getData()) { // meaning createTempFiles is set to true in the SeamFilter this.certificateBytes = FileUtils.readFileToByteArray(item.getFile()); } else { this.certificateBytes = item.getData(); } }
From source file:com.frostwire.android.gui.transfers.TransferManager.java
public BittorrentDownload downloadTorrent(String uri, TorrentFetcherListener fetcherListener, String tempDownloadTitle) { String url = uri.trim();/* w w w.j av a 2s. co m*/ try { if (url.contains("urn%3Abtih%3A")) { //fixes issue #129: over-encoded url coming from intent url = url.replace("urn%3Abtih%3A", "urn:btih:"); } if (isAlreadyDownloadingTorrentByUri(url)) { return null; } Uri u = Uri.parse(url); String scheme = u.getScheme(); if (!scheme.equalsIgnoreCase("file") && !scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https") && !scheme.equalsIgnoreCase("magnet")) { LOG.warn("Invalid URI scheme: " + u.toString()); return new InvalidBittorrentDownload(R.string.torrent_scheme_download_not_supported); } BittorrentDownload download = null; if (fetcherListener == null) { if (scheme.equalsIgnoreCase("file")) { BTEngine.getInstance().download(new File(u.getPath()), null, null); } else if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https") || scheme.equalsIgnoreCase("magnet")) { download = new TorrentFetcherDownload(this, new TorrentUrlInfo(u.toString(), tempDownloadTitle)); bittorrentDownloadsList.add(download); bittorrentDownloadsMap.put(download.getInfoHash(), download); } } else { if (scheme.equalsIgnoreCase("file")) { fetcherListener.onTorrentInfoFetched(FileUtils.readFileToByteArray(new File(u.getPath())), null, -1); } else if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https") || scheme.equalsIgnoreCase("magnet")) { // this executes the listener method when it fetches the bytes. download = new TorrentFetcherDownload(this, new TorrentUrlInfo(u.toString(), tempDownloadTitle), fetcherListener); bittorrentDownloadsList.add(download); bittorrentDownloadsMap.put(download.getInfoHash(), download); incrementStartedTransfers(); return download; } return null; } incrementStartedTransfers(); return download; } catch (Throwable e) { LOG.warn("Error creating download from uri: " + url, e); return new InvalidBittorrentDownload(R.string.torrent_scheme_download_not_supported); } }