List of usage examples for org.apache.commons.io FilenameUtils concat
public static String concat(String basePath, String fullFilenameToAdd)
From source file:com.enioka.jqm.api.ServiceSimple.java
@GET @Path("enginelog") @Produces(MediaType.TEXT_PLAIN)/*from w w w. ja v a 2s .co m*/ public String getEngineLog(@QueryParam("latest") int latest) { // Failsafe if (latest > 10000) { latest = 10000; } ReversedLinesFileReader r = null; try { File f = new File( FilenameUtils.concat("./logs/", "jqm-" + context.getInitParameter("jqmnode") + ".log")); r = new ReversedLinesFileReader(f); StringBuilder sb = new StringBuilder(latest); String buf = r.readLine(); int i = 1; while (buf != null && i <= latest) { sb.append(buf); sb.append(System.getProperty("line.separator")); i++; buf = r.readLine(); } return sb.toString(); } catch (Exception e) { throw new ErrorDto("Could not return the desired file", 8, e, Status.NO_CONTENT); } finally { IOUtils.closeQuietly(r); } }
From source file:cop.maven.plugins.AbstractRestToRamlMojoTest.java
@Test(groups = { "init", "checkOutputDirectoryExists" }) public void shouldSetDefaultOutputWhenOutputIsNotSet() throws Exception { File dir = TestUtils.createTempDir(); Build build = new Build(); build.setDirectory(dir.getAbsolutePath()); mojo.project.setBuild(build);// www. j a va 2 s .c o m checkOutputDirectoryExists(mojo); assertThat(mojo.out).isEqualTo(FilenameUtils.concat(dir.getAbsolutePath(), "docs")); }
From source file:com.mbrlabs.mundus.editor.core.kryo.KryoManager.java
/** * Saves a scene.//from w w w .j av a2 s.c o m * * @param context * project context of the scene * @param scene * scene to save */ public void saveScene(ProjectContext context, Scene scene) { try { String sceneDir = FilenameUtils.concat(context.path + "/" + ProjectManager.PROJECT_SCENES_DIR, scene.getName() + "." + ProjectManager.PROJECT_SCENE_EXTENSION); Output output = new Output(new FileOutputStream(sceneDir)); SceneDescriptor descriptor = DescriptorConverter.convert(scene); kryo.writeObject(output, descriptor); output.flush(); output.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:com.blueverdi.rosietheriveter.PhotoViewActivity.java
private Bitmap getBitmapFromAssets(String fileName) { String fn = FilenameUtils.concat(imageSource, fileName); Bitmap bit = null;/* ww w . ja v a 2 s. c om*/ try { InputStream bitmap = getAssets().open(fn); bit = BitmapFactory.decodeStream(bitmap); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return bit; }
From source file:com.stanley.captioner.Transcriber.java
public void start() { // Create stream speech recognizer. StreamSpeechRecognizer recognizer = null; try {//from w w w . j av a 2s .c o m recognizer = new StreamSpeechRecognizer(config); } catch (IOException e) { System.out.println("Failed to create recognizer."); } // Open print writer for writing text output. PrintWriter writer = null; try { writer = new PrintWriter(textOut); } catch (FileNotFoundException e) { System.out.println("Failed to create print writer."); } // Open stream for first pass. InputStream stream = null; try { stream = new FileInputStream(audio); } catch (FileNotFoundException e) { System.out.println("Failed to stream file."); } // Initialize loop variables. SpeechResult result; int resultCount = 0; Stats stats = recognizer.createStats(1); // Start recognizer for first pass. recognizer.startRecognition(stream); System.out.println("First pass (stats collection) started."); // First pass loop to collect statistics for model adaptation. while ((result = recognizer.getResult()) != null) { try { stats.collect(result); } catch (Exception e) { System.out.println("Failed to collect stats."); } resultCount++; // Toggle for testing. if (quickTest && resultCount > 5) { break; } } // Close recognizer (end of first pass). recognizer.stopRecognition(); System.out.println("Stats collection stopped."); // Transform model using model adaptation. Transform transform = stats.createTransform(); recognizer.setTransform(transform); // Reopen stream for second pass. stream = null; try { stream = new FileInputStream(audio); } catch (FileNotFoundException e) { System.out.println("Failed to stream file."); } // Start recognizer for second pass. recognizer.startRecognition(stream); System.out.println("Second pass started."); // Create output text file header. writer.printf("%-20s", "WORD:"); writer.printf("%20s", "CONFIDENCE:"); writer.printf("%20s", "START TIME:"); writer.printf("%20s", "END_TIME:"); writer.println(); for (int i = 0; i < 80; i++) { writer.print("-"); } writer.println(); // Initialize loop variables. int wordCount = 0; String sentence = ""; int sentenceLength = 0; long sentenceStart = 0; long sentenceEnd = 0; ArrayList<Sentence> sentences = new ArrayList<>(); // Second pass loop to calculate sentences. RECOG: while ((result = recognizer.getResult()) != null) { for (WordResult wordResult : result.getWords()) { wordCount++; String word = wordResult.getWord().toString(); double confidence = wordResult.getConfidence(); long startTime = wordResult.getTimeFrame().getStart(); long endTime = wordResult.getTimeFrame().getEnd(); writer.printf("%-20s", word); writer.printf("%20.1f", confidence); writer.printf("%20d", startTime); writer.printf("%20d", endTime); writer.println(); if (sentenceLength + word.length() < 40) { // Add to current sentence. sentence += " " + word; sentenceLength += word.length(); sentenceEnd = endTime; } else { // End of current sentence, store and start a new one. sentences.add(new Sentence(sentence, sentenceStart, sentenceEnd)); sentenceStart = sentenceEnd; sentence = ""; sentenceLength = 0; } // Toggle for testing. if (quickTest && wordCount > 50) { break RECOG; } } } // Close print writer and recognizer (end of second pass). writer.close(); recognizer.stopRecognition(); System.out.println("Second pass stopped."); // Create folder for caption images. String imageDirPath = FilenameUtils.concat(textOut.getParent(), FilenameUtils.getBaseName(textOut.getAbsolutePath())); System.out.println(imageDirPath); File imageDir = new File(imageDirPath); if (!imageDir.exists()) { // Create the folder if it doesn't already exist. imageDir.mkdir(); } // Calculate video output path. String videoOutPath = FilenameUtils.concat(textOut.getParent(), FilenameUtils.getBaseName(textOut.getAbsolutePath()) + ".mp4"); System.out.println(videoOutPath); // Initialize a command string for overlaying the captions. String commandString = String.format("%s -y -loglevel quiet -i %s", new Converter().getFFmpegPath(), videoIn.getAbsolutePath()); System.out.println(commandString); // Initialize a complex filter for overlaying the captions. String filterString = "-filter_complex"; // Acquire a probe object for collecting video details. Converter converter = new Converter(); FFprobe ffprobe = null; try { ffprobe = new FFprobe(converter.getFFprobePath()); } catch (IOException e) { System.out.println("Failed to find ffprobe."); } // Probe the video for details. FFmpegProbeResult probeResult = null; try { probeResult = ffprobe.probe(videoIn.getAbsolutePath()); } catch (IOException e) { System.out.println("Failed to probe video file."); } // Get the width and height of the video. FFmpegStream videoStream = probeResult.getStreams().get(0); int videoWidth = videoStream.width; int videoHeight = videoStream.height; // Calculate the x and y coordinates of the captions. int captionX = (videoWidth / 2) - 220; int captionY = videoHeight - 25 - 10; // Loop over the sentences, generate captions, and build command string. int k = 0; for (Sentence s : sentences) { // Create caption image from sentence. BufferedImage bi = new BufferedImage(440, 50, BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); g.setPaint(new Color(0, 0, 0, 128)); g.fillRect(0, 0, 440, 50); g.setPaint(new Color(255, 255, 255, 255)); g.setFont(new Font("Serif", Font.BOLD, 20)); FontMetrics fm = g.getFontMetrics(); int x = bi.getWidth() - fm.stringWidth(s.text) - 5; int y = fm.getHeight() - 5; g.drawString(s.text, x, y); g.dispose(); // Write the image to file for future reference. String suffix = String.format("caption-%03d.png", k); String imagePath = FilenameUtils.concat(imageDirPath, suffix); try { File imageFile = new File(imagePath); ImageIO.write(bi, "png", imageFile); } catch (IOException e) { System.out.println("Failed to write caption image to file."); } // Add the caption image path to the command string. commandString += " -i " + imagePath; // Add an entry to the complex filter with the caption timeframe. if (k == 0) { filterString += String.format(" \"[0:v][1:v] overlay=%d:%d:enable='between(t,%d,%d)'%s", captionX, captionY, s.startTime / 1000, s.endTime / 1000, (k == sentences.size() - 1) ? "\"" : " [tmp];"); } else { filterString += String.format(" [tmp][%d:v] overlay=%d:%d:enable='between(t,%d,%d)'%s", k + 1, captionX, captionY, s.startTime / 1000, s.endTime / 1000, (k == sentences.size() - 1) ? "\"" : " [tmp];"); } k++; } // Build final command string. String finalCommand = String.format("%s %s -codec:a copy %s", commandString, filterString, videoOutPath); System.out.println(finalCommand); // Attempt to run the final command string to embed the captions. try { Process p = Runtime.getRuntime().exec(finalCommand); try { if (p.waitFor() != 0) { // Embedding the captions failed. System.out.println("Image overlay failed."); } } catch (InterruptedException e) { // Embedding the captions was interrupted. System.out.println("Interrupted image overlay."); } } catch (IOException e) { // Command string failed to execute. System.out.println("Failed to execute image overlay."); } // Delete intermediate audio file. audio.delete(); System.out.println("........................CAPTIONING COMPLETE........................"); }
From source file:edu.cornell.med.icb.goby.alignments.TestPositionSlices.java
@Test public void testIndexLocations() throws IOException { final String basename = "align-position-slices-index-locations1"; buildAlignment(basename);//from ww w . ja va 2s . c o m {// check that we can read skipTo before the start of the slice and only get entries that are within the slice // boundaries. final AlignmentReader reader = new AlignmentReaderImpl(FilenameUtils.concat(BASE_TEST_DIR, basename)); reader.readHeader(); ObjectList<ReferenceLocation> locations = reader.getLocations(1); reader.close(); Assert.assertEquals(1, locations.get(0).targetIndex); Assert.assertEquals(12, locations.get(0).position); Assert.assertEquals(1, locations.get(1).targetIndex); Assert.assertEquals(13, locations.get(1).position); Assert.assertEquals(2, locations.get(2).targetIndex); Assert.assertEquals(123, locations.get(2).position); Assert.assertEquals(2, locations.get(3).targetIndex); Assert.assertEquals(300, locations.get(3).position); Assert.assertEquals(4, locations.size()); } }
From source file:edu.cornell.med.icb.goby.alignments.TestMerge.java
@Test public void testMergeWithTargetIds3() throws IOException { // Test that target indices are merged. align-105 and align-106 each have two targets. The result merged // target index should be between 0 and 3. Maximum index at 3. final Merge merger = new Merge(3); 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-105-merged"); merger.setK(2);// w w w . j a va2s .c o m merger.setSilent(false); merger.merge(inputFiles, outputFile); final AlignmentReader reader = new AlignmentReaderImpl(outputFile); int maxTargetIndex = -1; while (reader.hasNext()) { final Alignments.AlignmentEntry alignmentEntry = reader.next(); maxTargetIndex = Math.max(maxTargetIndex, alignmentEntry.getTargetIndex()); } assertEquals(3, maxTargetIndex); }
From source file:au.org.ala.delta.io.OutputFileManager.java
protected String prependOutputDirectory(String fileName) { if (StringUtils.isEmpty(fileName)) { return ""; }/*from www . j av a 2 s . co m*/ String outputFileName = FilenameUtils.separatorsToSystem(fileName); if (!outputFileName.contains(File.separator) && (_outputDirectory != null)) { outputFileName = FilenameUtils.concat(_outputDirectory, fileName); } return outputFileName; }
From source file:com.s2g.pst.resume.importer.PSTFileHelper.java
/** * */*from w ww .j a v a 2 s. c om*/ * * @param basePath * @param fileName * @param count * @return Return unique file name */ public void getUniqueFileName(String basePath, String fileName, int count) { // if (this.uniqueFileName != null) { // return; // } File file = null; if (count <= 0) { file = new File(FilenameUtils.concat(basePath, fileName)); } else { file = new File(basePath + File.separator + FilenameUtils.removeExtension(fileName) + "_" + count + "." + FilenameUtils.getExtension(fileName)); } if (file.exists()) { getUniqueFileName(basePath, fileName, count + 1); } else { this.uniqueFileName = file.getName(); System.out.println("called : " + this.uniqueFileName); } // return ;//this.uniqueFileName; }
From source file:edu.cornell.med.icb.goby.alignments.TestAlignmentIndex.java
@Test public void test_1_9_5_IndexIssueWithSkipTo() throws IOException { int[] targetLengths = new int[] { 100, 50, 20, 10, 5 }; final String basename1 = FilenameUtils.concat(BASE_TEST_DIR, "align-index-error-2"); final AlignmentWriterImpl writer = new AlignmentWriterImpl(basename1); writer.setTargetLengths(targetLengths); writer.setNumAlignmentEntriesPerChunk(1); writer.setSorted(true);/*w ww . j a v a2s . c o m*/ 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.readHeader(); Alignments.AlignmentEntry entry = reader.skipTo(1, 0); 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()); }