List of usage examples for org.apache.commons.io FilenameUtils getBaseName
public static String getBaseName(String filename)
From source file:de.xirp.profile.ProfileGenerator.java
/** * Generates a BOT file with the given path from the given * {@link de.xirp.profile.Robot robot} bean. * /*from w w w . j a v a 2 s . co m*/ * @param robot * The robot to generate the XML for. * @param botFile * The file to write the result to. Must be the full path. * * @throws JAXBException if the given robot was null, or something * went wrong generating the xml. * @throws FileNotFoundException if something went wrong generating the xml. */ public static void generateBOT(Robot robot, File botFile) throws FileNotFoundException, JAXBException { if (robot == null) { throw new JAXBException(I18n.getString("ProfileGenerator.exception.robotNull")); //$NON-NLS-1$ } String fileName = FilenameUtils.getBaseName(botFile.getName()); JAXBContext jc = JAXBContext.newInstance(Robot.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(robot, new FileOutputStream( Constants.CONF_ROBOTS_DIR + File.separator + fileName + Constants.ROBOT_POSTFIX)); }
From source file:de.tudarmstadt.ukp.dkpro.core.testing.IOTestRunner.java
public static void testOneWay2(Class<? extends CollectionReader> aReader, Class<? extends AnalysisComponent> aWriter, String aExpectedFile, String aOutputFile, String aFile, Object... aExtraParams) throws Exception { String outputFolder = aReader.getSimpleName() + "-" + FilenameUtils.getBaseName(aFile); if (DkproTestContext.get() != null) { outputFolder = DkproTestContext.get().getTestOutputFolderName(); }/*w ww . jav a 2 s. com*/ File reference = new File("src/test/resources/" + aExpectedFile); File input = new File("src/test/resources/" + aFile); File output = new File("target/test-output/" + outputFolder); List<Object> extraReaderParams = new ArrayList<>(); extraReaderParams.add(ComponentParameters.PARAM_SOURCE_LOCATION); extraReaderParams.add(input); extraReaderParams.addAll(asList(aExtraParams)); CollectionReaderDescription reader = createReaderDescription(aReader, extraReaderParams.toArray()); List<Object> extraWriterParams = new ArrayList<>(); if (!ArrayUtils.contains(aExtraParams, ComponentParameters.PARAM_TARGET_LOCATION)) { extraWriterParams.add(ComponentParameters.PARAM_TARGET_LOCATION); extraWriterParams.add(output); } extraWriterParams.add(ComponentParameters.PARAM_STRIP_EXTENSION); extraWriterParams.add(true); extraWriterParams.addAll(asList(aExtraParams)); AnalysisEngineDescription writer = createEngineDescription(aWriter, extraWriterParams.toArray()); runPipeline(reader, writer); String expected = FileUtils.readFileToString(reference, "UTF-8"); String actual = FileUtils.readFileToString(new File(output, aOutputFile), "UTF-8"); assertEquals(expected.trim(), actual.trim()); }
From source file:gov.nih.nci.caarray.plugins.illumina.BgxDesignHandler.java
/** * {@inheritDoc}/*from ww w . ja v a 2 s.c om*/ */ @Override public void load(ArrayDesign arrayDesign) { arrayDesign.setName(FilenameUtils.getBaseName(this.designFile.getName())); arrayDesign.setLsidForEntity(IlluminaCsvDesignHandler.LSID_AUTHORITY + ":" + IlluminaCsvDesignHandler.LSID_NAMESPACE + ":" + arrayDesign.getName()); try { arrayDesign.setNumberOfFeatures(getNumberOfFeatures()); } catch (final IOException e) { LOG.error(e); throw new IllegalStateException("Couldn't read file: ", e); } }
From source file:jp.co.tis.gsp.tools.dba.mojo.LoadDataMojo.java
@Override protected void executeMojoSpec() throws MojoExecutionException, MojoFailureException { List<File> files = CollectionsUtil .newArrayList(FileUtils.listFiles(dataDirectory, new String[] { "csv" }, true)); DriverManagerUtil.registerDriver(driver); Connection conn = null;/* www . j ava2 s .c o m*/ try { conn = DriverManager.getConnection(url, user, password); conn.setAutoCommit(false); } catch (SQLException e) { getLog().error( "DB?????????driver??url?????????????"); throw new MojoExecutionException("", e); } // ???? EntityDependencyParser parser = new EntityDependencyParser(); Dialect dialect = DialectFactory.getDialect(url); parser.parse(conn, url, dialect.normalizeSchemaName(schema)); final List<String> tableList = parser.getTableList(); Collections.sort(files, new Comparator<File>() { @Override public int compare(File f1, File f2) { return getIndex(FilenameUtils.getBaseName(f1.getName())) - getIndex(FilenameUtils.getBaseName(f2.getName())); } private int getIndex(String tableName) { for (int i = 0; i < tableList.size(); i++) { if (StringUtil.equalsIgnoreCase(tableName, tableList.get(i))) { return i; } } return 0; } }); try { for (File file : files) { CsvReader reader = null; String fileName = file.getName(); FileInputStream in = FileInputStreamUtil.create(file); try { getLog().info("????:" + fileName); if (specifiedEncodingFiles != null && specifiedEncodingFiles.containsKey(fileName)) { String encoding = (String) specifiedEncodingFiles.get(fileName); reader = new CsvReader(in, Charset.forName(encoding)); getLog().info(" -- encoding:" + encoding); } else { reader = new CsvReader(in, SJIS); } String tableName = StringUtils.upperCase(FilenameUtils.getBaseName(fileName)); reader.readHeaders(); String[] headers = reader.getHeaders(); CsvInsertHandler insertHandler = new CsvInsertHandler(conn, dialect, dialect.normalizeSchemaName(schema), tableName, headers); insertHandler.prepare(); while (reader.readRecord()) { String[] values = reader.getValues(); for (int i = 0; i < values.length; i++) { insertHandler.setObject(i + 1, values[i]); } insertHandler.execute(); } insertHandler.close(); } catch (IOException e) { getLog().warn("??????:" + file, e); } catch (SQLException e) { getLog().warn("SQL??????:" + file, e); } finally { if (reader != null) reader.close(); } } } finally { ConnectionUtil.close(conn); } }
From source file:com.textocat.textokit.morph.lemmatizer.util.NormalizedTextWriter.java
@Override public void process(JCas cas) throws AnalysisEngineProcessException { // initialize String docFilename;/* www .j a v a 2 s. co m*/ try { docFilename = DocumentUtils.getDocumentFilename(cas.getCas()); } catch (URISyntaxException e) { throw new AnalysisEngineProcessException(e); } if (docFilename == null) { throw new IllegalStateException("Can't extract a document filename from CAS"); } String outFilename = FilenameUtils.getBaseName(docFilename) + OUTPUT_FILENAME_SUFFIX + OUTPUT_FILENAME_EXTENSION; File outFile = new File(outputDir, outFilename); Map<Token, Word> token2WordIndex = MorphCasUtils.getToken2WordIndex(cas); @SuppressWarnings("unchecked") FSIterator<TokenBase> tbIter = (FSIterator) cas.getAnnotationIndex(TokenBase.typeIndexID).iterator(); try (PrintWriter out = IoUtils.openPrintWriter(outFile)) { Token lastProcessedTok = null; for (Token curTok : JCasUtil.select(cas, Token.class)) { // normalize space between out.print(normalizeSpaceBetween(tbIter, lastProcessedTok, curTok)); // normalize current token String curTokNorm; Word w = token2WordIndex.get(curTok); if (w != null) { curTokNorm = MorphCasUtils.getFirstLemma(w); } else { curTokNorm = curTok.getCoveredText(); } out.print(curTokNorm); // lastProcessedTok = curTok; } // handle a possible line ending after the last token out.print(normalizeSpaceBetween(tbIter, lastProcessedTok, null)); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } }
From source file:com.mbrlabs.mundus.assets.FbxConv.java
public FbxConvResult execute() { FbxConvResult result = new FbxConvResult(); if (input == null || output == null) { result.setSuccess(false);//from w w w . j ava2 s . c o m result.setResultCode(FbxConvResult.RESULT_CODE_PARAM_ERROR); Log.error(TAG, "FbxCov input or output not defined"); return result; } if (!input.endsWith("fbx")) { result.setSuccess(false); result.setResultCode(FbxConvResult.RESULT_CODE_WRONG_INPUT_FORMAT); Log.error(TAG, "FbxCov input format not supported"); } // build arguments String outputFilename = FilenameUtils.getBaseName(input); List<String> args = new ArrayList<String>(6); if (flipTexture) args.add("-f"); if (verbose) args.add("-v"); if (outputFormat == OUTPUT_FORMAT_G3DJ) { args.add("-o"); args.add("g3dj"); outputFilename += ".g3dj"; } else { outputFilename += ".g3db"; } args.add(input); String path = FilenameUtils.concat(output, outputFilename); args.add(path); Log.debug("FbxConv", "Command: " + args); pb.command().addAll(args); // execute fbx-conv process try { Process process = pb.start(); int exitCode = process.waitFor(); String log = IOUtils.toString(process.getInputStream()); if (exitCode == 0 && !log.contains("ERROR")) { result.setSuccess(true); result.setOutputFile(path); } result.setLog(log); } catch (IOException e) { e.printStackTrace(); result.setSuccess(false); result.setResultCode(FbxConvResult.RESULT_CODE_IO_ERROR); } catch (InterruptedException e) { e.printStackTrace(); result.setSuccess(false); result.setResultCode(FbxConvResult.RESULT_CODE_INTERRUPTED); } return result; }
From source file:com.gmail.frogocomics.schematic.BiomeWorldV2Object.java
public static BiomeWorldV2Object load(File file) throws IOException { BufferedReader settingsReader; if (!file.exists()) { throw new FileNotFoundException(); }//w w w. j a v a 2 s. c o m settingsReader = new BufferedReader(new FileReader(file)); int lineNumber = 0; String thisLine; ArrayList<BiomeWorldObjectBlock> bo2Blocks = new ArrayList<>(); while ((thisLine = settingsReader.readLine()) != null) { lineNumber++; if (Pattern.compile("[0-9]").matcher(thisLine.substring(0, 1)).matches() || thisLine.substring(0, 1).equalsIgnoreCase("-")) { //Example: -1,-1,5:18.4 // x,z,y:id.data String[] location = thisLine.split(":")[0].split(","); String[] block = thisLine.split(":")[1].split("\\."); bo2Blocks.add(new BiomeWorldObjectBlock(Integer.parseInt(location[0]), Integer.parseInt(location[2]), Integer.parseInt(location[1]), Short.parseShort(block[0]), Byte.parseByte(block[1]))); } } ArrayList<Integer> maxXMap = new ArrayList<>(); ArrayList<Integer> maxYMap = new ArrayList<>(); ArrayList<Integer> maxZMap = new ArrayList<>(); for (BiomeWorldObjectBlock bo2 : bo2Blocks) { maxXMap.add(bo2.getX()); maxYMap.add(bo2.getY()); maxZMap.add(bo2.getZ()); } int maxX = Collections.max(maxXMap); int maxY = Collections.max(maxYMap); int maxZ = Collections.max(maxZMap); int minX = Collections.min(maxXMap); int minY = Collections.min(maxYMap); int minZ = Collections.min(maxZMap); int differenceX = maxX - minX + 1; int differenceY = maxY - minY + 1; int differenceZ = maxZ - minZ + 1; HashMap<Integer, Set<BiomeWorldObjectBlock>> blocks = new HashMap<>(); for (int i = 0; i < differenceY + 1; i++) { blocks.put(i, new HashSet<>()); } for (BiomeWorldObjectBlock bo2 : bo2Blocks) { Set<BiomeWorldObjectBlock> a = blocks.get(bo2.getY() - minY); a.add(bo2); blocks.replace(bo2.getY(), a); } //System.out.println(differenceX + " " + differenceZ); SliceStack schematic = new SliceStack(differenceY, differenceX, differenceZ); for (Map.Entry<Integer, Set<BiomeWorldObjectBlock>> next : blocks.entrySet()) { Slice slice = new Slice(differenceX, differenceZ); for (BiomeWorldObjectBlock block : next.getValue()) { //System.out.println("Added block at " + String.valueOf(block.getX() - minX) + "," + String.valueOf(block.getZ() - minZ)); slice.setBlock(block.getBlock(), block.getX() - minX, block.getZ() - minZ); } schematic.addSlice(slice); } //System.out.println(schematic.toString()); return new BiomeWorldV2Object(schematic, FilenameUtils.getBaseName(file.getAbsolutePath())); }
From source file:io.gravitee.gateway.registry.mongodb.AbstractMongoDBTest.java
@Before public void setup() throws Exception { mockStatic(PropertiesUtils.class); factory = MongodForTestsFactory.with(Version.Main.DEVELOPMENT); mongoClient = factory.newMongo();/*w w w. j a v a2s.com*/ LOG.info("Creating database '{}'...", DATABASE_NAME); mongoDatabase = mongoClient.getDatabase(DATABASE_NAME); final ServerAddress mongoAddress = mongoClient.getAddress(); when(PropertiesUtils.getProperty(any(Properties.class), eq("gravitee.io.mongodb.host"))) .thenReturn(mongoAddress.getHost()); when(PropertiesUtils.getProperty(any(Properties.class), eq("gravitee.io.mongodb.database"))) .thenReturn(mongoDatabase.getName()); when(PropertiesUtils.getPropertyAsInteger(any(Properties.class), eq("gravitee.io.mongodb.port"))) .thenReturn(mongoAddress.getPort()); final File file = new File(AbstractMongoDBTest.class.getResource(getJsonDataSetResourceName()).toURI()); final String collectionName = FilenameUtils.getBaseName(file.getName()); LOG.info("Creating collection '{}'...", collectionName); final MongoCollection<Document> collection = mongoDatabase.getCollection(collectionName); final List<DBObject> dbObjects = (List<DBObject>) JSON.parse(FileUtils.readFileToString(file)); for (final DBObject dbObject : dbObjects) { final Document document = new Document(); for (final String key : dbObject.keySet()) { document.put(key, dbObject.get(key)); } collection.insertOne(document); } }
From source file:gov.nih.nci.caarray.platforms.unparsed.UnparsedArrayDesignFileHandler.java
/** * {@inheritDoc}/*from ww w . j av a 2 s. c om*/ */ @Override public boolean openFiles(Set<CaArrayFile> designFiles) { if (designFiles == null || designFiles.size() != 1 || !LSID_TEMPLATE_MAP.containsKey(designFiles.iterator().next().getFileType())) { return false; } this.designFile = designFiles.iterator().next(); final LSID lsidTemplate = LSID_TEMPLATE_MAP.get(this.designFile.getFileType()); this.designLsid = new LSID(lsidTemplate.getAuthority(), lsidTemplate.getNamespace(), FilenameUtils.getBaseName(this.designFile.getName())); return true; }
From source file:com.nuvolect.deepdive.util.OmniUtil.java
/** * Return a unique file given the current file as a model. * Example if file exists: /Picture/mypic.jpg > /Picture/mypic~.jpg * @return/*from w w w.j a va 2 s. c o m*/ */ public static OmniFile makeUniqueName(OmniFile initialFile) { String path = initialFile.getPath(); String basePath = FilenameUtils.getFullPath(path); // path without name String baseName = FilenameUtils.getBaseName(path); // name without extension String extension = FilenameUtils.getExtension(path); // extension String volumeId = initialFile.getVolumeId(); String dot = "."; if (extension.isEmpty()) dot = ""; OmniFile file = initialFile; while (file.exists()) { baseName += "~"; String fullPath = basePath + baseName + dot + extension; file = new OmniFile(volumeId, fullPath); } return file; }