List of usage examples for org.apache.commons.io FilenameUtils concat
public static String concat(String basePath, String fullFilenameToAdd)
From source file:com.zappy.purefit6.service.WeekFacadeREST.java
/** * Creates new week program./*from w w w. jav a 2 s . c om*/ * @param uploadedInputStream Image file FORM * @param fileDetail Image details FORM * @param name Name FORM */ @POST @Consumes(MediaType.MULTIPART_FORM_DATA) public void create(@FormDataParam("image") InputStream uploadedInputStream, @FormDataParam("image") FormDataContentDisposition fileDetail, @FormDataParam("name") String name) { try { //Copy file File destination = new File( FilenameUtils.concat("/home/gianksp/Desktop/test/week", fileDetail.getFileName())); FileUtils.copyInputStreamToFile(uploadedInputStream, destination); //Create element Week week = new Week(); week.setName(name); week.setImagePath(destination.getAbsolutePath()); //Store element super.create(week); } catch (IOException ex) { log.log(Level.SEVERE, "Unable to import week program image " + " .name:" + name + " .fileName:" + fileDetail.getName(), ex); } catch (Exception ex) { log.log(Level.SEVERE, "Unable to create week program " + " .name:" + name, ex); } }
From source file:de.tudarmstadt.ukp.dkpro.keyphrases.bookindexing.evaluation.phrasematch.TokenReader.java
@Override public List<String> getListOfStrings(final JCas jcas) throws AnalysisEngineProcessException { String goldPhrases;//w w w. j a va2s .com try { goldPhrases = FileUtils.readFileToString( new File(FilenameUtils.concat(path, getDocumentBaseName(jcas) + normalizeSuffix(suffix)))); } catch (final IOException e) { throw new AnalysisEngineProcessException(new Throwable(e)); } final List<String> result = new ArrayList<String>(); for (String goldPhrase : goldPhrases.split(delimiter)) { goldPhrase = lowercase ? goldPhrase.toLowerCase() : goldPhrase; goldPhrase = goldPhrase.trim(); if (!goldPhrase.isEmpty()) result.add(goldPhrase); } return result; }
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractServiceProviderLogoController.java
private void logoResponse(String imagePath, String defaultImagePath, HttpServletResponse response) { FileInputStream fileinputstream = null; String rootImageDir = config.getValue(Names.com_citrix_cpbm_portal_settings_images_uploadPath); if (rootImageDir != null && !rootImageDir.trim().equals("")) { try {/*from w ww.j ava 2 s. co m*/ if (imagePath != null && !imagePath.trim().equals("")) { String absoluteImagePath = FilenameUtils.concat(rootImageDir, imagePath); fileinputstream = new FileInputStream(absoluteImagePath); if (fileinputstream != null) { int numberBytes = fileinputstream.available(); byte bytearray[] = new byte[numberBytes]; fileinputstream.read(bytearray); response.setContentType("image/" + FilenameUtils.getExtension(imagePath)); // TODO:Set Cache headers for browser to force browser to cache to reduce load OutputStream outputStream = response.getOutputStream(); response.setContentLength(numberBytes); outputStream.write(bytearray); outputStream.flush(); outputStream.close(); fileinputstream.close(); return; } } } catch (FileNotFoundException e) { logger.debug("###File not found in retrieving logo"); } catch (IOException e) { logger.debug("###IO Error in retrieving logo"); } } response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); response.setHeader("Location", defaultImagePath); }
From source file:net.sf.jvifm.control.MiscFileCommand.java
private String replacePath(String path) { if (path.startsWith(".") || path.startsWith(File.separator)) return path; return FilenameUtils.concat(pwd, path); }
From source file:de.tor.tribes.util.AttackToTextWriter.java
private static boolean writeBlocksToFiles(List<String> pBlocks, Tribe pTribe, File pPath) { int fileNo = 1; String baseFilename = pTribe.getName().replaceAll("\\W+", ""); for (String block : pBlocks) { String fileName = FilenameUtils.concat(pPath.getPath(), baseFilename + fileNo + ".txt"); FileWriter w = null;/*ww w . j av a 2s . c om*/ try { w = new FileWriter(fileName); w.write(block); w.flush(); w.close(); } catch (IOException ioe) { logger.error("Failed to write attack to textfile", ioe); return false; } finally { if (w != null) { try { w.close(); } catch (IOException ignored) { } } } fileNo++; } return true; }
From source file:avantssar.aslanpp.testing.LibraryTestTask.java
public LibraryTestTask(ISpecProvider specProvider, File modelsDir) throws IOException { this.specProvider = specProvider; ASLanPPSpecification spec = specProvider.getASLanPPSpecification(); StringBuffer sb = new StringBuffer(); sb.append(spec.getSpecificationName()); if (specProvider instanceof IChannelModelFlexibleSpecProvider) { IChannelModelFlexibleSpecProvider cmFlex = (IChannelModelFlexibleSpecProvider) specProvider; sb.append("_"); sb.append(cmFlex.getChannelModel().toString()); if (specProvider instanceof IChannelTypeFlexibleSpecProvider) { IChannelTypeFlexibleSpecProvider ctFlex = (IChannelTypeFlexibleSpecProvider) specProvider; sb.append("_"); sb.append(ctFlex.getChannelType().type.toString()); }/*from w w w . j a v a 2 s . c o m*/ } String baseFileName = sb.toString(); sb.append(".aslan++"); spec.setSpecificationName(baseFileName); aslanPP = new File(FilenameUtils.concat(modelsDir.getAbsolutePath(), sb.toString())); aslan = new File(FilenameUtils.removeExtension(aslanPP.getAbsolutePath()) + ".aslan"); FileUtils.writeStringToFile(aslanPP, spec.toString()); TranslatorOptions options = new TranslatorOptions(); IASLanSpec aslanSpec = specProvider.getExpectedASLanTranslation(options); aslanSpec.getHornClauses(); if (aslanSpec != null) { FileUtils.writeStringToFile(aslan, aslanSpec.getStrippedRepresentation()); } }
From source file:edu.cornell.med.icb.goby.counts.TestCountsArchive.java
@Test public void testWriter() throws IOException { final String basename = FilenameUtils.concat(BASE_TEST_DIR, "101.bin"); final CountsArchiveWriter writer = new CountsArchiveWriter(basename); CountsWriterI cw = writer.newCountWriter(0, "count-0"); cw.appendCount(0, 10000);//from ww w . j a v a 2s. c om cw.appendCount(10, 10000); cw.appendCount(20, 10000); cw.close(); writer.returnWriter(cw); // read counts 1 cw = writer.newCountWriter(1, "count-1"); cw.appendCount(0, 20000); cw.appendCount(10, 20000); cw.appendCount(20, 20000); cw.appendCount(30, 20000); cw.close(); writer.returnWriter(cw); writer.close(); final CountsArchiveReader reader = new CountsArchiveReader(basename); assertTrue("Since Goby 1.9.7 reader must have stats.", reader.isStatsParsed()); CountsReader cr = reader.getCountReader("count-1"); assertTrue(cr.hasNextTransition()); cr.nextTransition(); assertTrue(cr.hasNextTransition()); cr.nextTransition(); assertTrue(cr.hasNextTransition()); cr.nextTransition(); assertEquals(20, cr.getCount()); assertTrue(cr.hasNextTransition()); cr.nextTransition(); assertEquals(30, cr.getCount()); assertFalse(cr.hasNextTransition()); cr.close(); // read counts 0 cr = reader.getCountReader("count-0"); assertTrue(cr.hasNextTransition()); cr.nextTransition(); assertTrue(cr.hasNextTransition()); cr.nextTransition(); assertTrue(cr.hasNextTransition()); cr.nextTransition(); assertEquals(20, cr.getCount()); assertFalse(cr.hasNextTransition()); cr.close(); // and again counts-1 cr = reader.getCountReader("count-1"); assertTrue(cr.hasNextTransition()); cr.nextTransition(); assertTrue(cr.hasNextTransition()); cr.nextTransition(); assertTrue(cr.hasNextTransition()); cr.nextTransition(); assertEquals(20, cr.getCount()); assertTrue(cr.hasNextTransition()); cr.nextTransition(); assertEquals(30, cr.getCount()); assertFalse(cr.hasNextTransition()); cr.close(); }
From source file:au.org.ala.delta.dist.DISTTest.java
private void checkResults(String path, String resultFileName, boolean compareAsFloats) throws Exception { java.io.File expectedFile = new File(FilenameUtils.concat(path, "expected_results/" + resultFileName)); String expected = FileUtils.readFileToString(expectedFile, "cp1252"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(path, resultFileName)); String actual = FileUtils.readFileToString(actualFile, "cp1252"); System.out.print(actual);//from www . j av a 2s . co m expected = replaceNewLines(expected); if (compareAsFloats) { String[] actualFloats = actual.trim().split("\\s+"); String[] expectedFloats = expected.trim().split("\\s+"); for (int i = 0; i < expectedFloats.length; i++) { float float1 = Float.valueOf(actualFloats[i]); float float2 = Float.valueOf(expectedFloats[i]); assertEquals("index " + i, float2, float1, 0.001f); } } assertEquals(expected, actual); }
From source file:com.xiaomi.linden.service.LindenServer.java
public LindenServer(String conf) throws Exception { File lindenProperties = new File(FilenameUtils.concat(conf, LINDEN_PROPERTIES)); File schemaXml = new File(FilenameUtils.concat(conf, SCHEMA_XML)); Preconditions.checkArgument(lindenProperties.exists(), "can not find linden.properties."); lindenConf = LindenConfigBuilder.build(lindenProperties); if (schemaXml.exists()) { LindenSchema schema = LindenSchemaBuilder.build(schemaXml); lindenConf.setSchema(schema);//w w w .j a v a2 s. c o m } else { throw new Exception("schema.xml not found."); } port = lindenConf.getPort(); Preconditions.checkNotNull(lindenConf.getLogPath(), "log path can not be null."); System.setProperty(LOG_PATH, lindenConf.getLogPath()); System.setProperty(LOG4J_SHUTDOWN_HOOK_ENABLED, "false"); System.setProperty(LOG4J_CONTEXT_SELECTOR, "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector"); LoggerContext ctx = (LoggerContext) LogManager.getContext(false); ctx.setConfigLocation(new File(FilenameUtils.concat(conf, LOG4j2_XML)).toURI()); ctx.reconfigure(); LOGGER = LoggerFactory.getLogger(LindenServer.class); }
From source file:edu.cornell.med.icb.goby.alignments.TestAlignmentIndex.java
/** * This test triggers an issue with Goby 1.9.5 indices. Using pre 1.9.6 indices, the skipTo method could fail * to return alignments if they occured at a position after the length of the next sequence. This test will fail * with any version of Goby prior to 1.9.6, and will success with Goby 1.9.6. Old alignments can be upgraded to * the index structures used by Goby 1.9.6 with the goby upgrade mode. * * @throws IOException/*from ww w . j a va 2s . c o m*/ */ @Test public void test_1_9_5_IndexIssue() throws IOException { int[] targetLengths = new int[] { 100, 50, 20, 10, 5 }; final String basename1 = FilenameUtils.concat(BASE_TEST_DIR, "align-index-error-1"); final AlignmentWriterImpl writer = new AlignmentWriterImpl(basename1); writer.setTargetLengths(targetLengths); writer.setNumAlignmentEntriesPerChunk(1); writer.setSorted(true); int queryIndex = 0; writer.setAlignmentEntry(queryIndex++, 0, 99, 30, false, constantQueryLength); writer.appendEntry(); writer.setAlignmentEntry(queryIndex++, 1, 0, 30, false, constantQueryLength); writer.appendEntry(); writer.setAlignmentEntry(queryIndex++, 1, 1, 30, false, constantQueryLength); writer.appendEntry(); writer.close(); AlignmentReaderImpl reader = new AlignmentReaderImpl(basename1); reader.reposition(0, 99); Alignments.AlignmentEntry entry = reader.next(); assertEquals(0, entry.getTargetIndex()); assertEquals(99, entry.getPosition()); entry = reader.next(); assertEquals(1, entry.getTargetIndex()); assertEquals(0, entry.getPosition()); entry = reader.next(); assertEquals(1, entry.getTargetIndex()); assertEquals(1, entry.getPosition()); assertFalse(reader.hasNext()); // Now check that the locations were stored in the index and can be decoded correctly: ObjectList<ReferenceLocation> locations = reader.getLocations(1); assertEquals(0, locations.get(0).targetIndex); assertEquals(99, locations.get(0).position); assertEquals(1, locations.get(1).targetIndex); assertEquals(0, locations.get(1).position); assertEquals(1, locations.get(2).targetIndex); assertEquals(1, locations.get(2).position); assertEquals("with modulo=1, must recover three locations.", 3, locations.size()); }