List of usage examples for org.apache.commons.io FilenameUtils getBaseName
public static String getBaseName(String filename)
From source file:com.consol.citrus.admin.service.TestCaseServiceImpl.java
@Override public Long getTestCount(Project project) { Long testCount = Long.valueOf(FileUtils.getTestFiles(getTestDirectory(project)).size()); try {//from w w w.j ava2 s.co m Resource[] javaSources = new PathMatchingResourcePatternResolver().getResources( "file:" + FilenameUtils.separatorsToUnix(getJavaDirectory(project)) + "**/*.java"); for (Resource resource : javaSources) { File file = resource.getFile(); String testName = FilenameUtils.getBaseName(file.getName()); String testPackage = file.getParentFile().getAbsolutePath() .substring(getJavaDirectory(project).length()).replace(File.separatorChar, '.'); if (knownToClasspath(testPackage, testName)) { testCount += getTestCaseInfoFromClass(testPackage, testName, file).size(); } else { testCount += getTestCaseInfoFromFile(testPackage, testName, file).size(); } } } catch (IOException e) { log.warn("Failed to read Java source files - list of test cases for this project is incomplete", e); } return testCount; }
From source file:edu.cornell.med.icb.goby.modes.SplitFastaMode.java
/** * Split a fasta / fastq file by (a) readlength and (b) the maximum number of * entries per file. This will output the files that are written to stdout * @throws IOException error reading / writing files. *//*from ww w .j av a 2 s . c o m*/ @Override public void execute() throws IOException { final FastXReader reader = new FastXReader(inputFile); final Int2ObjectMap<PrintStream> outputMap = new Int2ObjectOpenHashMap<PrintStream>(); final Int2IntMap entriesPerReadLen = new Int2IntOpenHashMap(); final Int2IntMap filesPerReadLen = new Int2IntOpenHashMap(); final List<String> removeExt = Arrays.asList("gz", "fa", "mpfa", "fna", "fsa", "fas", "fasta", "fq", "mpfq", "fnq", "fsq", "fas", "fastq"); String inputName = FilenameUtils.getName(inputFile); while (true) { // Remove the unwanted extensions from the file name final String ext = FilenameUtils.getExtension(inputName); if (!removeExt.contains(ext)) { break; } inputName = FilenameUtils.getBaseName(inputName); } final String outputFilenameTemplate = FilenameUtils.getFullPath(inputFile) + inputName + "._READLENGTH_._PART_." + reader.getFileType(); final NumberFormat nf3 = NumberFormat.getInstance(); nf3.setMinimumIntegerDigits(3); final NumberFormat nf2 = NumberFormat.getInstance(); nf2.setMinimumIntegerDigits(2); for (final FastXEntry entry : reader) { final int readLen = Math.min(fastxSplitMaxLength, roundReadLen(entry.getReadLength(), splitReadsMod)); PrintStream out = outputMap.get(readLen); if (out == null) { filesPerReadLen.put(readLen, 1); entriesPerReadLen.put(readLen, 0); String outputFilename = outputFilenameTemplate.replaceAll("_READLENGTH_", nf3.format(readLen)); outputFilename = outputFilename.replaceAll("_PART_", nf2.format(1)); System.out.println(outputFilename); out = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFilename))); outputMap.put(readLen, out); } int numEntries = entriesPerReadLen.get(readLen); if (numEntries == maxReadsPerFile) { out.close(); numEntries = 0; int numFiles = filesPerReadLen.get(readLen); numFiles++; filesPerReadLen.put(readLen, numFiles); String outputFilename = outputFilenameTemplate.replaceAll("_READLENGTH_", nf3.format(readLen)); outputFilename = outputFilename.replaceAll("_PART_", nf2.format(numFiles)); System.out.println(outputFilename); out = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFilename))); outputMap.put(readLen, out); } out.println(entry.getEntry()); entriesPerReadLen.put(readLen, numEntries + 1); } for (final PrintStream out : outputMap.values()) { out.close(); } outputMap.clear(); reader.close(); }
From source file:me.jaimegarza.syntax.test.java.TestJavaPackedParser.java
@Test public void test03Runtime() throws ParsingException, AnalysisException, OutputException, MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException { generateLanguageFile(packedArgs);//from ww w. j av a2 s . co m File source = new File(tmpLanguageFile); File sourceDir = source.getParentFile(); CompilationResult result = compileJavaFile(source, sourceDir); Assert.assertEquals(result.getErrors().length, 0, "Syntax errors found trying to execute"); URL urls[] = new URL[1]; urls[0] = sourceDir.toURI().toURL(); URLClassLoader classLoader = URLClassLoader.newInstance(urls, this.getClass().getClassLoader()); String className = FilenameUtils.getBaseName(tmpLanguageFile); Class<?> clazz = classLoader.loadClass(className); Object parser = clazz.newInstance(); Method setVerbose = parser.getClass().getMethod("setVerbose", boolean.class); Method parse = parser.getClass().getMethod("parse"); Method getTotal = parser.getClass().getMethod("getTotal"); setVerbose.invoke(parser, true); parse.invoke(parser); Object o = getTotal.invoke(parser); Assert.assertTrue(o instanceof Integer); Integer i = (Integer) o; Assert.assertEquals((int) i, -17, "total does not match"); }
From source file:be.fedict.eid.dss.portal.control.bean.UploadBean.java
@Override public void listener(UploadEvent event) throws Exception { this.log.debug("listener"); UploadItem item = event.getUploadItem(); this.log.debug("filename: #0", item.getFileName()); this.filename = item.getFileName(); this.log.debug("content type: #0", item.getContentType()); String extension = FilenameUtils.getExtension(this.filename).toLowerCase(); this.contentType = supportedFileExtensions.get(extension); if (null == this.contentType) { /*//w w w.j a v a 2s . c o m * Unsupported content-type is converted to a ZIP container. */ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream); ZipEntry zipEntry = new ZipEntry(this.filename); zipOutputStream.putNextEntry(zipEntry); IOUtils.write(item.getData(), zipOutputStream); zipOutputStream.close(); this.filename = FilenameUtils.getBaseName(this.filename) + ".zip"; this.document = outputStream.toByteArray(); this.contentType = "application/zip"; return; } this.log.debug("file size: #0", item.getFileSize()); this.log.debug("data bytes available: #0", (null != item.getData())); if (null != item.getData()) { this.document = item.getData(); return; } File file = item.getFile(); if (null != file) { this.log.debug("tmp file: #0", file.getAbsolutePath()); this.document = FileUtils.readFileToByteArray(file); } }
From source file:MSUmpire.LCMSPeakStructure.LCMSPeakMS1.java
public String GetDefaultPepXML() { return FilenameUtils.separatorsToUnix(FilenameUtils.getFullPath(ScanCollectionName) + "interact-" + FilenameUtils.getBaseName(ScanCollectionName) + ".pep.xml"); }
From source file:com.googlecode.dex2jar.tools.JarAccessCmd.java
@Override protected void doCommandLine() throws Exception { if (remainingArgs.length != 1) { usage();//from w ww . j a va 2 s . co m return; } File jar = new File(remainingArgs[0]); if (!jar.exists()) { System.err.println(jar + " is not exists"); usage(); return; } if (output == null) { if (jar.isDirectory()) { output = new File(jar.getName() + "-access.jar"); } else { output = new File(FilenameUtils.getBaseName(jar.getName()) + "-access.jar"); } } if (output.exists() && !forceOverwrite) { System.err.println(output + " exists, use --force to overwrite"); usage(); return; } final int rf = ~str2acc(removeFieldAccess); final int rm = ~str2acc(removeMethodAccess); final int rc = ~str2acc(removeClassAccess); final int af = str2acc(addFieldAccess); final int am = str2acc(addMethodAccess); final int ac = str2acc(addClassAccess); final int flags = removeDebug ? ClassReader.SKIP_DEBUG : 0; final OutHandler fo = FileOut.create(output, true); try { new FileWalker().withStreamHandler(new StreamHandler() { @Override public void handle(boolean isDir, String name, StreamOpener current, Object nameObject) throws IOException { if (isDir || !name.endsWith(".class")) { fo.write(isDir, name, current == null ? null : current.get(), nameObject); return; } OutputStream os = null; try { InputStream is = current.get(); final ClassReader r = new ClassReader(is); ClassWriter cr = new ClassWriter(0); r.accept(new ClassAdapter(cr) { @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { int na = (access & rc) | ac; if (access != na) { System.out.println("c " + name); } super.visit(version, na, name, signature, superName, interfaces); } @Override public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { int na = (access & rf) | af; if (na != access) { System.out.println("f " + r.getClassName() + "." + name); } return super.visitField(na, name, desc, signature, value); } @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { int na = (access & rm) | am; if (na != access) { System.out.println("m " + r.getClassName() + "." + name + desc); } return super.visitMethod(na, name, desc, signature, exceptions); } }, flags | ClassReader.EXPAND_FRAMES); fo.write(isDir, name, cr.toByteArray(), nameObject); } catch (IOException ioe) { System.err.println("error in " + name); ioe.printStackTrace(System.err); } finally { IOUtils.closeQuietly(os); } } }).walk(jar); } finally { IOUtils.closeQuietly(fo); } }
From source file:me.jaimegarza.syntax.test.java.TestJavaExpandedParser.java
@Test public void test03Runtime() throws ParsingException, AnalysisException, OutputException, MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException { generateLanguageFile(expandedArgs);/*from w ww . java 2 s .com*/ File source = new File(tmpLanguageFile); File sourceDir = source.getParentFile(); CompilationResult result = compileJavaFile(source, sourceDir); Assert.assertEquals(result.getErrors().length, 0, "Syntax errors found trying to execute"); URL urls[] = new URL[1]; urls[0] = sourceDir.toURI().toURL(); URLClassLoader classLoader = URLClassLoader.newInstance(urls, this.getClass().getClassLoader()); String className = FilenameUtils.getBaseName(tmpLanguageFile); Class<?> clazz = classLoader.loadClass(className); Object parser = clazz.newInstance(); Method setVerbose = parser.getClass().getMethod("setVerbose", boolean.class); Method parse = parser.getClass().getMethod("parse"); Method getTotal = parser.getClass().getMethod("getTotal"); setVerbose.invoke(parser, true); parse.invoke(parser); Object o = getTotal.invoke(parser); Assert.assertTrue(o instanceof Integer); Integer i = (Integer) o; Assert.assertEquals((int) i, -17, "total does not match"); }
From source file:me.jaimegarza.syntax.test.java.TestJavaExpandedScanner.java
@Test public void test03Runtime() throws ParsingException, AnalysisException, OutputException, MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException { generateLanguageFile(packedArgs);/*w ww. j a v a 2 s.c o m*/ File source = new File(tmpLanguageFile); File sourceDir = source.getParentFile(); CompilationResult result = compileJavaFile(source, sourceDir); Assert.assertEquals(result.getErrors().length, 0, "Syntax errors found trying to execute"); URL urls[] = new URL[1]; urls[0] = sourceDir.toURI().toURL(); URLClassLoader classLoader = URLClassLoader.newInstance(urls, this.getClass().getClassLoader()); String className = FilenameUtils.getBaseName(tmpLanguageFile); Class<?> clazz = classLoader.loadClass(className); String lexicalClassName = className + "$StackElement"; Class<?> lexicalClazz = classLoader.loadClass(lexicalClassName); Object parser = clazz.newInstance(); Method setVerbose = parser.getClass().getMethod("setVerbose", boolean.class); Method init = parser.getClass().getMethod("init"); Method parse = parser.getClass().getMethod("parse", Integer.TYPE, lexicalClazz); Method getValidTokens = parser.getClass().getMethod("getValidTokens"); Method getTotal = parser.getClass().getMethod("getTotal"); setVerbose.invoke(parser, true); init.invoke(parser); for (Parameter p : parameters) { int[] tokens = (int[]) getValidTokens.invoke(parser); Assert.assertTrue(arrayContains(tokens, p.token), "Token " + p.token + " ain't there"); Object lexicalValue = lexicalClazz.newInstance(); Method setNumber = lexicalClazz.getMethod("setNumber", Integer.TYPE); setNumber.invoke(lexicalValue, p.value); parse.invoke(parser, p.token, lexicalValue); Object t = getTotal.invoke(parser); Assert.assertEquals(((Integer) t).intValue(), p.result, "Result is not " + p.result); } Object o = getTotal.invoke(parser); Assert.assertTrue(o instanceof Integer); Integer i = (Integer) o; Assert.assertEquals((int) i, -17, "total does not match"); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopExportDisplay.java
private void openFileAction(String finalFileName, ExportDataProvider dataProvider) { File destFile = null;//from w w w. j a v a 2s . co m try { destFile = File.createTempFile("get_" + FilenameUtils.getBaseName(finalFileName), "." + getFileExt(finalFileName)); } catch (IOException e) { String message = messages.getMessage(DesktopExportDisplay.class, "export.tempFileError"); getFrame().getWindowManager().showNotification(message, Frame.NotificationType.WARNING); } if (destFile != null) { if (Desktop.isDesktopSupported() && saveFile(dataProvider, destFile)) { try { Desktop.getDesktop().open(destFile); } catch (IOException ex) { String message = messages.getMessage(DesktopExportDisplay.class, "export.openError"); getFrame().getWindowManager().showNotification(message, Frame.NotificationType.WARNING); } } } }
From source file:edu.cornell.med.icb.goby.modes.SequenceVariationStatsMode.java
/** * Display sequence variations.//from w ww . j a v a2s .c o m * * @throws java.io.IOException error reading / writing */ @Override public void execute() throws IOException { PrintStream stream = null; try { stream = outputFilename == null ? System.out : new PrintStream(new FileOutputStream(outputFilename)); switch (outputFormat) { case TAB_DELIMITED: case TSV: stream.println( "basename\tread-index\tcount-variation-bases\tbases-at-index/all-variations-bases\tbases-at-index/all-reference-bases\tcount-reference-bases"); break; } for (final String basename : basenames) { alignmentIterator.resetTallies(); final String[] singleBasename = { basename }; // Iterate through each alignment and write sequence variations to output file: alignmentIterator.iterate(singleBasename); final Long2LongMap readIndexTallies = alignmentIterator.getReadIndexVariationTally(); final double totalNumberOfVariationBases = sum(readIndexTallies.values()); final double numberOfAlignmentEntries = alignmentIterator.getNumAlignmentEntries(); final long countReferenceBases = alignmentIterator.getReferenceBaseCount(); for (final long readIndex : readIndexTallies.keySet()) { final long countVariationBasesAtReadIndex = readIndexTallies.get(readIndex); final double frequency = ((double) countVariationBasesAtReadIndex) / totalNumberOfVariationBases; final double alignFrequency = ((double) countVariationBasesAtReadIndex) / countReferenceBases; stream.printf("%s\t%d\t%d\t%s\t%f\t%d%n", FilenameUtils.getBaseName(basename), readIndex, countVariationBasesAtReadIndex, frequency, alignFrequency, countReferenceBases); } stream.flush(); } } finally { if (stream != System.out) { IOUtils.closeQuietly(stream); } } }