List of usage examples for org.apache.commons.io FilenameUtils concat
public static String concat(String basePath, String fullFilenameToAdd)
From source file:edu.cornell.med.icb.goby.alignments.TestMerge.java
@Test public void testMergeWithTargetIds2() throws IOException { final Merge merger = new Merge(30); final List<File> inputFiles = new ArrayList<File>(); inputFiles.add(new File(FilenameUtils.concat(BASE_TEST_DIR, "align-105"))); inputFiles.add(new File(FilenameUtils.concat(BASE_TEST_DIR, "align-106"))); final String outputFile = FilenameUtils.concat(BASE_TEST_DIR, "out-106-merged"); merger.setK(1);/*from ww w . ja v a 2 s . c o m*/ merger.merge(inputFiles, outputFile); // With k=1 and twice the same input file, the merge should keep zero entries final int count = countAlignmentEntries(outputFile); assertEquals(0, count); }
From source file:es.urjc.mctwp.image.impl.analyze.AnalyzeImagePlugin.java
private File convert(Image image, String format) throws ImageException { String options = null;//from w w w. j av a 2s. c o m File result = null; File source = null; try { if (image instanceof SingleAnalyzeImageImpl) { source = ((SingleAnalyzeImageImpl) image).getContent(); options = "-c " + format + " -e 1"; } else if (image instanceof ComplexAnalyzeImageImpl) { source = ((ComplexAnalyzeImageImpl) image).getHeader(); options = "-c " + format + " -e 1 -fv"; } String base = source.getParent(); String pre = ImageUtils.getFileName(source); String exten = (DCM_FORMAT_OPT.equalsIgnoreCase(format)) ? ".dcm" : ".png"; result = new File(FilenameUtils.concat(base, pre + exten)); // Check if thumbnails exists. Like a cache of thumbnails if ((!result.exists()) || (!result.isFile()) || (result.length() == 0)) { // Delete a possible erroneous thumbnail file if (result.exists()) result.delete(); // Execute transformation and scale String cmd = medconPath + " " + options + " -f " + source.getAbsolutePath() + " -o " + result.getAbsolutePath(); exec(cmd, true); if (PNG_FORMAT_OPT.equals(format)) scaleThumbnail(result); } } catch (Exception e) { if (result.exists()) result.delete(); logger.error(e.getMessage()); throw new ImageException(e); } return result; }
From source file:com.mbrlabs.mundus.editor.core.kryo.KryoManager.java
/** * Loads a scene.//from w w w . j a v a 2 s .c o m * * Does however not initialize ModelInstances, Terrains, ... -> * ProjectManager * * @param context * project context of the scene * @param sceneName * name of the scene to load * @return loaded scene * @throws FileNotFoundException */ public SceneDescriptor loadScene(ProjectContext context, String sceneName) throws FileNotFoundException { String sceneDir = FilenameUtils.concat(context.path + "/" + ProjectManager.PROJECT_SCENES_DIR, sceneName + "." + ProjectManager.PROJECT_SCENE_EXTENSION); Input input = new Input(new FileInputStream(sceneDir)); SceneDescriptor sceneDescriptor = kryo.readObjectOrNull(input, SceneDescriptor.class); return sceneDescriptor; }
From source file:com.mbrlabs.mundus.core.project.ProjectManager.java
/** * Loads the project context for a project. * * This does not open to that project, it only loads it. * * @param ref project reference to the project * @return loaded project context * @throws FileNotFoundException if project can't be found *//*from w ww .j a v a2 s. c o m*/ public ProjectContext loadProject(ProjectRef ref) throws FileNotFoundException { ProjectContext context = kryoManager.loadProjectContext(ref); context.path = ref.getPath(); // load textures for (MTexture tex : context.textures) { tex.texture = TextureUtils .loadMipmapTexture(Gdx.files.absolute(FilenameUtils.concat(context.path, tex.getPath())), true); Log.debug("Loaded texture: " + tex.getPath()); } // load g3db models G3dModelLoader loader = new G3dModelLoader(new UBJsonReader()); for (MModel model : context.models) { model.setModel( loader.loadModel(Gdx.files.absolute(FilenameUtils.concat(context.path, model.g3dbPath)))); } // load terrain .terra files for (Terrain terrain : context.terrains) { TerrainIO.importTerrain(context, terrain); } context.currScene = loadScene(context, context.activeSceneName); return context; }
From source file:edu.kit.dama.rest.util.RestClientUtils.java
/** * Deserializes an entity from a stream provided by a ClientResponse. * <b>Attention:</b>May throw a DeserializationException if the * deserialization fails for some reason. In some cases, pEntityClass might * be 'null', e.g. if no deserializable output is expected. In this cases it * is possible, to obtain the response object by setting the return type C * to ClientResponse. If this is the case and pEntityClass is null, * pResponse will be returned./*from w w w . ja v a 2 s . c o m*/ * * @param <C> entity class of ClientResponse if pResponse should be * returned. * @param pEntityClass The class of the entity to deserialize or null if no * deserializable result is expected. * @param pResponse The response which provides the entity input stream and * the HTTP result. * * @return The deserialized object or pResponse. */ public static <C> C createObjectFromStream(final Class<C> pEntityClass, final ClientResponse pResponse) { C returnValue = null; if (pResponse == null) { throw new WebServiceException( "Failed to create object from stream. No response availabe! (response == null)"); } if (pResponse.getStatus() != 200) { //error ... do not try to deserialize the result. try { String data = new String(IOUtils.toByteArray(pResponse.getEntityInputStream())); String tmp = FileUtils.getTempDirectoryPath(); String extension = ".html"; if (!data.contains("<html>")) { extension = ".log"; } String outputFile = FilenameUtils.concat(tmp, "kitdm_rest_" + System.currentTimeMillis() + extension); try (FileOutputStream fout = new FileOutputStream(outputFile)) { fout.write(data.getBytes()); fout.flush(); } throw new WebServiceException("Failed to create object from stream. Service call returned status " + pResponse.getStatus() + ". More information available at: " + outputFile); } catch (IOException ex) { throw new WebServiceException("Failed to create object from stream. Service call returned status " + pResponse.getStatus() + ". Cause: See server log."); } } else if (pEntityClass != null) { return pResponse.getEntity(pEntityClass); /* try { Unmarshaller unmarshaller = org.eclipse.persistence.jaxb.JAXBContext.newInstance(pEntityClass).createUnmarshaller(); returnValue = (C) unmarshaller.unmarshal(getInputStream(pResponse.getEntityInputStream())); if (LOGGER.isDebugEnabled()) { Marshaller marshaller = org.eclipse.persistence.jaxb.JAXBContext.newInstance(pEntityClass).createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter sw = new StringWriter(); marshaller.marshal(returnValue, sw); LOGGER.debug("createObjectFromStream: " + sw.toString()); } } catch (JAXBException ex) { throw new DeserializationException("Failed to deserialize object of type " + pEntityClass + " from response " + pResponse, ex); }*/ } else { try { //check if the ClientResponse is expected as result... returnValue = (C) pResponse; } catch (ClassCastException e) { LOGGER.debug("No response expected!"); returnValue = null; } } return returnValue; }
From source file:edu.cornell.med.icb.goby.alignments.TestReadWriteAlignments.java
@Test public void readWriteHeader104() throws IOException { final IndexedIdentifier queryIds = new IndexedIdentifier(); // NOTE: there is no id for entry 0, this is ok queryIds.put(new MutableString("query:1"), 1); queryIds.put(new MutableString("query:2"), 2); final IndexedIdentifier targetIds = new IndexedIdentifier(); targetIds.put(new MutableString("target:0"), 0); targetIds.put(new MutableString("target:1"), 1); final AlignmentWriter writer = new AlignmentWriterImpl(FilenameUtils.concat(BASE_TEST_DIR, "align-104")); assertNotNull("Query ids should not be null", queryIds.keySet()); writer.setQueryIdentifiers(queryIds); assertNotNull("Target ids should not be null", targetIds.keySet()); writer.setTargetIdentifiers(targetIds); final int[] targetLengths = { 42, 42 }; writer.setTargetLengths(targetLengths); writer.close();/*from www .jav a 2s. c om*/ final AlignmentReaderImpl reader = new AlignmentReaderImpl( FilenameUtils.concat(BASE_TEST_DIR, "align-104")); reader.readHeader(); assertEquals("Number of queries do not match", 2, reader.getNumberOfQueries()); }
From source file:net.sf.jvifm.ui.ZipLister.java
private File extractToTemp(FileObject fileObject) { String basename = fileObject.getName().getBaseName(); File tempFile = null;//from w w w.j av a 2 s. co m try { String tmpPath = System.getProperty("java.io.tmpdir"); tempFile = new File(FilenameUtils.concat(tmpPath, basename)); byte[] buf = new byte[4096]; BufferedInputStream bin = new BufferedInputStream(fileObject.getContent().getInputStream()); BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(tempFile)); while (bin.read(buf, 0, 1) != -1) { bout.write(buf, 0, 1); } bout.close(); bin.close(); // by barney } catch (Throwable e) { e.printStackTrace(); } return tempFile; }
From source file:io.hawkcd.agent.services.FileManagementService.java
@Override public String pathCombine(String... args) { String output = ""; for (String arg : args) { arg = this.normalizePath(arg); output = FilenameUtils.concat(output, arg); }/*from ww w .j a v a 2 s .co m*/ FilenameUtils.normalizeNoEndSeparator(output); return output; }
From source file:edu.udo.scaffoldhunter.model.clustering.evaluation.FileSaverMetaModule.java
private String getUniqueBaseName(EvaluationResult result) { count++;/*from ww w .j a va 2s. c o m*/ return FilenameUtils.concat(FilenameUtils.getFullPathNoEndSeparator(path), FilenameUtils.getBaseName(path)) + "-" + result.getMeasurement() + "_" + Integer.toString(count - 1); }
From source file:ddf.catalog.resource.download.ReliableResourceDownloader.java
public ResourceResponse setupDownload(Metacard metacard, DownloadStatusInfo downloadStatusInfo) { Resource resource = resourceResponse.getResource(); MimeType mimeType = resource.getMimeType(); String resourceName = resource.getName(); fbos = new FileBackedOutputStream(DEFAULT_FILE_BACKED_OUTPUT_STREAM_THRESHOLD); countingFbos = new CountingOutputStream(fbos); streamReadByClient = new ReliableResourceInputStream(fbos, countingFbos, downloadState, downloadIdentifier, resourceResponse);// w w w .ja v a 2s . co m this.metacard = metacard; // Create new ResourceResponse to return that will encapsulate the // ReliableResourceInputStream that will be read by the client simultaneously as the product // is cached to disk (if caching is enabled) ResourceImpl newResource = new ResourceImpl(streamReadByClient, mimeType, resourceName); resourceResponse = new ResourceResponseImpl(resourceResponse.getRequest(), resourceResponse.getProperties(), newResource); // Get handle to retrieved product's InputStream resourceInputStream = resource.getInputStream(); eventListener.setDownloadMap(downloadIdentifier, resourceResponse); downloadStatusInfo.addDownloadInfo(downloadIdentifier, this, resourceResponse); if (downloaderConfig.isCacheEnabled()) { CacheKey keyMaker = null; String key = null; try { keyMaker = new CacheKey(metacard, resourceResponse.getRequest()); key = keyMaker.generateKey(); } catch (IllegalArgumentException e) { LOGGER.info("Cannot create cache key for resource with metacard ID = {}", metacard.getId()); return resourceResponse; } if (!resourceCache.isPending(key)) { // Fully qualified path to cache file that will be written to. // Example: // <INSTALL-DIR>/data/product-cache/<source-id>-<metacard-id> // <INSTALL-DIR>/data/product-cache/ddf.distribution-abc123 filePath = FilenameUtils.concat(resourceCache.getProductCacheDirectory(), key); reliableResource = new ReliableResource(key, filePath, mimeType, resourceName, metacard); resourceCache.addPendingCacheEntry(reliableResource); try { fos = FileUtils.openOutputStream(new File(filePath)); doCaching = true; this.downloadState.setCacheEnabled(true); } catch (IOException e) { LOGGER.info("Unable to open cache file {} - no caching will be done.", filePath); } } else { LOGGER.debug("Cache key {} is already pending caching", key); } } return resourceResponse; }