List of usage examples for org.apache.commons.io FilenameUtils removeExtension
public static String removeExtension(String filename)
From source file:org.crazyt.xgogdownloader.Util.java
public final int createXML(String filepath, int chunk_size, String xml_dir) { int res = 0;// ww w.j a va 2 s. com File infile; int filesize; int size; int chunks; int i; if (xml_dir == "") { xml_dir = ".cache/xgogdownloader/xml"; } // end of if File path = Factory.newFile(xml_dir); if (!path.exists()) { if (!path.mkdirs()) { System.out.println("Failed to create directory: " + path); } } infile = Factory.newFile(filepath); // RandomAccessFile file = new RandomAccessFile("file.txt", "rw");? // fseek/seek ftell/getFilePointer rewind/seek(0) if (infile.exists()) { filesize = (int) infile.length(); } else { System.out.println(filepath + " doesn't exist"); return res; } // end of if-else // Get filename String filename = FilenameUtils.removeExtension(infile.getName()); String filenameXML = xml_dir + "/" + filename + ".xml"; System.out.println(filename); // Determine number of chunks int remaining = filesize % chunk_size; chunks = (remaining == 0) ? filesize / chunk_size : (filesize / chunk_size) + 1; System.out.println("Filesize: " + filesize + " bytes"); System.out.println("Chunks: " + chunks); System.out.println("Chunk size: " + (chunk_size / Math.pow(2.0, 20.0)) + " MB"); Util util_md5 = new Util(); String file_md5 = util_md5.getFileHash(filepath); System.out.println("MD5: " + file_md5); Element fileElem = new Element("file"); fileElem.setAttribute(new Attribute("name", filename)); fileElem.setAttribute(new Attribute("md5", file_md5)); fileElem.setAttribute(new Attribute("chunks", String.valueOf(chunks))); fileElem.setAttribute(new Attribute("total_size", String.valueOf(filesize))); System.out.println("Getting MD5 for chunks"); for (i = 0; i < chunks; i++) { int range_begin = i * chunk_size; // fseek(infile, range_begin, SEEK_SET); if ((i == chunks - 1) && (remaining != 0)) { chunk_size = remaining; } int range_end = range_begin + chunk_size - 1; String chunk = String.valueOf(chunk_size * 4); String hash = util_md5.getChunkHash(chunk); // calculates hash of // chunk string? Element chunkElem = new Element("chunk"); chunkElem.setAttribute(new Attribute("id", String.valueOf(i))); chunkElem.setAttribute(new Attribute("from", String.valueOf(range_begin))); chunkElem.setAttribute(new Attribute("to", String.valueOf(range_begin))); chunkElem.setAttribute(new Attribute("method", "md5")); chunkElem.addContent(new Text(hash)); fileElem.addContent(chunkElem); System.out.println("Chunks hashed " + (i + 1) + " / " + chunks + "\r"); } Document doc = new Document(fileElem); System.out.println("Writing XML: " + filenameXML); try { XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(doc, Factory.newFileWriter(filenameXML)); res = 1; } catch (IOException e) { System.out.println("Can't create " + filenameXML); return res; } return res; }
From source file:org.cytoscape.MetScape.data.CompoundData.java
public static CompoundData parse(File compoundFile) { CompoundData ret = null;/*www .j a va 2 s . c o m*/ try { CompoundData ex = new CompoundData(); DataFile base; if (compoundFile.getName().endsWith(".xls") || compoundFile.getName().endsWith(".xlsx")) { base = new ExcelFile(compoundFile); } else { base = new TextFile(compoundFile); } ex.name = FilenameUtils.removeExtension(compoundFile.getName()); int startRow = base.getStartRowIndex(); int endRow = base.getEndRowIndex(); int startCol = 0; for (int i = 1; i <= base.getEndColIndex(0); i++) { if (isDataColumn(i, base)) { startCol = i; break; } } int endCol = startCol; if (startCol > 0) { for (int i = startCol; i <= base.getEndColIndex(0); i++) { if (base.getString(0, i + 1) == null) break; endCol++; } } if (endCol > 0) { ex.columns = new String[endCol - startCol + 1]; for (int col = startCol; col <= endCol; col++) { String s = base.getString(0, col); ex.columns[col - startCol] = CharMatcher.WHITESPACE.trimFrom(s); ex.columnIsSigned.put(CharMatcher.WHITESPACE.trimFrom(s), false); } } // get remaining rows, the data startRow++; for (int row = startRow; row < (endRow + 1); row++) { String nameOrId = base.getString(row, 0); if (nameOrId == null) continue; nameOrId = CharMatcher.WHITESPACE.trimFrom(nameOrId); Double[] data = null; if (startCol > 0) { data = new Double[ex.columns.length]; for (int col = 0; col <= endCol - startCol; col++) { data[col] = base.getDouble(row, col + startCol); if (data[col] != null && data[col] < 0) { ex.columnIsSigned.put(ex.columns[col], true); } } } ex.addRecord(nameOrId, data); } ret = ex; } catch (Throwable t) { t.printStackTrace(); } return ret; }
From source file:org.cytoscape.MetScape.data.ConceptData.java
public static ConceptData parse(File conceptFile) { ConceptData ret = null;/*from w ww . j a v a 2 s. c o m*/ try { ConceptData ex = new ConceptData(); DataFile base; if (conceptFile.getName().endsWith(".xls") || conceptFile.getName().endsWith(".xlsx")) base = new ExcelFile(conceptFile); else base = new TextFile(conceptFile); ex.name = FilenameUtils.removeExtension(conceptFile.getName()); int startRow = base.getStartRowIndex(); int endRow = base.getEndRowIndex(); // first row - labels; ignore for now startRow++; for (int row = startRow; row < (endRow + 1); row++) { if (base.getString(row, 0) == null || base.getString(row, 0).equals("") || StrUtils.splitCommaOrSpaceSeparatedString(base.getString(row, 8)) == null || StrUtils.splitCommaOrSpaceSeparatedString(base.getString(row, 8)).isEmpty() || CharMatcher.WHITESPACE.trimFrom(base.getString(row, 8)).equals("")) continue; Concept rec = ex.makeRecord(); rec.setConceptName(base.getString(row, 0)); rec.setConceptType(base.getString(row, 1)); rec.setNumUniqueGenes(base.getInteger(row, 2)); rec.setCoeff(base.getDouble(row, 3)); rec.setOddsRatio(base.getDouble(row, 4)); rec.setPvalue(base.getDouble(row, 5)); rec.setFdr(base.getDouble(row, 6)); rec.setDirection(base.getString(row, 7)); rec.setGeneIdsOrSymbols( StrUtils.splitCommaOrSpaceSeparatedString(makeIdValue(base.getString(row, 8)))); ex.addRecord(rec); } ret = ex; } catch (Throwable t) { t.printStackTrace(); } return ret; }
From source file:org.cytoscape.MetScape.data.CorrelationData.java
public static CorrelationData parse(File correlationFile) { CorrelationData ret = null;// www. j a v a 2 s . c o m try { CorrelationData ex = new CorrelationData(); DataFile base; if (correlationFile.getName().endsWith(".xls") || correlationFile.getName().endsWith(".xlsx")) base = new ExcelFile(correlationFile); else base = new TextFile(correlationFile); if (base.getEndColIndex(0) != NUMCOLS - 1) { showFormatErrorMessage(); return null; } ex.name = FilenameUtils.removeExtension(correlationFile.getName()); int startRow = base.getStartRowIndex(); int endRow = base.getEndRowIndex(); int edgeDataCol = 0; for (int i = 1; i <= base.getEndColIndex(0); i++) { if (isDataColumn(i, base)) { edgeDataCol = i; break; } } if (edgeDataCol == 0) { showFormatErrorMessage(); return null; } else { ex.columns = new String[1]; String s = base.getString(0, edgeDataCol); ex.columns[0] = CharMatcher.WHITESPACE.trimFrom(s); ex.columnIsSigned.put(CharMatcher.WHITESPACE.trimFrom(s), false); } int sourceNodeCol = -1; int targetNodeCol = -1; for (int i = 0; i < NUMCOLS; i++) { if (i == edgeDataCol) { continue; } if (sourceNodeCol == -1) { sourceNodeCol = i; } else { targetNodeCol = i; } } // get remaining rows, the data startRow++; for (int row = startRow; row < (endRow + 1); row++) { String sourceNameOrId = base.getString(row, sourceNodeCol); if (sourceNameOrId == null) { continue; } sourceNameOrId = CharMatcher.WHITESPACE.trimFrom(sourceNameOrId); String targetNameOrId = base.getString(row, targetNodeCol); if (targetNameOrId == null) { targetNameOrId = ""; } else { targetNameOrId = CharMatcher.WHITESPACE.trimFrom(targetNameOrId); } Double data = base.getDouble(row, edgeDataCol); if (data == null) { data = Double.NaN; } else if (data < 0) { ex.columnIsSigned.put(ex.columns[0], true); // force negative correlations to 0 data = 0.0; } ex.addRecord(sourceNameOrId, targetNameOrId, data); } ret = ex; } catch (Throwable t) { t.printStackTrace(); } return ret; }
From source file:org.cytoscape.MetScape.data.GeneData.java
public static GeneData parse(File geneFile) { GeneData ret = null;// ww w. j a v a2 s.c om try { GeneData ex = new GeneData(); DataFile base; if (geneFile.getName().endsWith(".xls") || geneFile.getName().endsWith(".xlsx")) base = new ExcelFile(geneFile); else base = new TextFile(geneFile); ex.name = FilenameUtils.removeExtension(geneFile.getName()); int startRow = base.getStartRowIndex(); int endRow = base.getEndRowIndex(); int startCol = 0; for (int i = 1; i <= base.getEndColIndex(0); i++) { if (isDataColumn(i, base)) { startCol = i; break; } } int endCol = startCol; if (startCol > 0) { for (int i = startCol; i <= base.getEndColIndex(0); i++) { if (base.getString(0, i + 1) == null) break; endCol++; } } if (endCol > 0) { ex.columns = new String[endCol - startCol + 1]; for (int col = startCol; col <= endCol; col++) { String s = base.getString(0, col); ex.columns[col - startCol] = CharMatcher.WHITESPACE.trimFrom(s); ex.columnIsSigned.put(CharMatcher.WHITESPACE.trimFrom(s), false); } } startRow++; for (int row = startRow; row < (endRow + 1); row++) { String geneId = base.getString(row, 0); if (geneId == null) continue; geneId = makeIdValue(geneId); Double[] data = null; if (startCol > 0) { data = new Double[ex.columns.length]; for (int col = 0; col <= endCol - startCol; col++) { data[col] = base.getDouble(row, col + startCol); if (data[col] != null && data[col] < 0) { ex.columnIsSigned.put(ex.columns[col], true); } } } ex.addRecord(geneId, data); } ret = ex; } catch (Throwable t) { t.printStackTrace(); } return ret; }
From source file:org.dataconservancy.packaging.impl.deposit.Config.java
private static String fileName(final PackagedResource resource) { String name = new File(resource.getURI().getPath()).getName(); if (!NONRDFSOURCE.equals(resource.getType())) { name = FilenameUtils.removeExtension(name); }// w w w . ja v a 2 s .com try { return URLEncoder.encode(name, "UTF-8"); } catch (final Exception e) { throw new RuntimeException(e); } }
From source file:org.datavyu.models.project.Project.java
/** * Sets the name of the project.// w w w.j av a2 s.c o m * * @param newProjectName * The new name to use for this project. */ public void setProjectName(final String newProjectName) { // Check Pre-conditions. assert (newProjectName != null); // Set the name of the project. String name = FilenameUtils.removeExtension(FilenameUtils.getName(newProjectName)); if ("".equals(name)) { name = "Project1"; } projectName = name; }
From source file:org.dbgl.util.DFendReloadedImportThread.java
public void doFancyStuff(Object obj, StringBuffer messageLog) throws IOException, SQLException { File profFile = (File) obj; Conf dfendExtra = new Conf(profFile, ps); String title = dfendExtra.getSettings().getValue("ExtraInfo", "name"); displayTitle(settings.msg("dialog.dfendimport.importing", new Object[] { title })); boolean favorite = dfendExtra.getSettings().getValue("ExtraInfo", "favorite").equals("1"); String setup = dfendExtra.getSettings().getValue("Extra", "setup"); if (StringUtils.isNotEmpty(setup)) { setup = FileUtils//www .j a va2s. co m .canonical(new File(dfendPath, dfendExtra.getSettings().getValue("Extra", "setup")).getPath()) .getPath(); } String setupParams = dfendExtra.getSettings().getValue("Extra", "setupparameters"); String notes = fixCRLF(dfendExtra.getSettings().getValue("ExtraInfo", "notes")); String dev = dfendExtra.getSettings().getValue("ExtraInfo", "developer"); String pub = dfendExtra.getSettings().getValue("ExtraInfo", "publisher"); String gen = dfendExtra.getSettings().getValue("ExtraInfo", "genre"); String year = dfendExtra.getSettings().getValue("ExtraInfo", "year"); String language = dfendExtra.getSettings().getValue("ExtraInfo", "language"); String userInfo = dfendExtra.getSettings().getValue("ExtraInfo", "userinfo"); if (StringUtils.isNotEmpty(userInfo)) { userInfo = StringUtils.join(StringUtils.split(fixCRLF(userInfo), "\n"), ", "); } String status = settings.msg("dialog.dfendimport.defaultprofilestatus"); int devId = KeyValuePair.findIdByValue(dbase.readDevelopersList(), dev); int publId = KeyValuePair.findIdByValue(dbase.readPublishersList(), pub); int genId = KeyValuePair.findIdByValue(dbase.readGenresList(), gen); int yrId = KeyValuePair.findIdByValue(dbase.readYearsList(), year); int statId = KeyValuePair.findIdByValue(dbase.readStatusList(), status); String[] customStrings = new String[] { language, "", "", "", userInfo, "", "", "" }; int[] custIDs = CUST_IDS; for (int i = 0; i < 4; i++) { custIDs[i] = KeyValuePair.findIdByValue(dbase.readCustomList(i), customStrings[i]); } String[] links = { fixWWW(dfendExtra.getSettings().getValue("ExtraInfo", "www")), fixWWW(dfendExtra.getSettings().getValue("ExtraInfo", "www2")), fixWWW(dfendExtra.getSettings().getValue("ExtraInfo", "www3")), fixWWW(dfendExtra.getSettings().getValue("ExtraInfo", "www4")), fixWWW(dfendExtra.getSettings().getValue("ExtraInfo", "www5")), fixWWW(dfendExtra.getSettings().getValue("ExtraInfo", "www6")), fixWWW(dfendExtra.getSettings().getValue("ExtraInfo", "www7")), fixWWW(dfendExtra.getSettings().getValue("ExtraInfo", "www8")) }; String[] linkTitles = { dfendExtra.getSettings().getValue("ExtraInfo", "wwwname"), dfendExtra.getSettings().getValue("ExtraInfo", "www2name"), dfendExtra.getSettings().getValue("ExtraInfo", "www3name"), dfendExtra.getSettings().getValue("ExtraInfo", "www4name"), dfendExtra.getSettings().getValue("ExtraInfo", "www5name"), dfendExtra.getSettings().getValue("ExtraInfo", "www6name"), dfendExtra.getSettings().getValue("ExtraInfo", "www7name"), dfendExtra.getSettings().getValue("ExtraInfo", "www8name") }; Profile newProfile = dbase.addOrEditProfile(title, dev, pub, gen, year, status, notes, favorite, new String[] { setup, "", "" }, new String[] { setupParams, "", "" }, devId, publId, genId, yrId, statId, defaultDBVersion.getId(), links, linkTitles, customStrings, CUST_INTS, custIDs, -1); Conf dfendProfile = new Conf( new File(confsPath, FilenameUtils.removeExtension(profFile.getName()) + FileUtils.CONF_EXT), title, newProfile.getId(), defaultDBVersion, ps); String cap = dfendProfile.getSettings().getValue("dosbox", "captures"); String dstCap = FileUtils.constructCapturesDir(newProfile.getId()); String dstCapRelative = FileUtils.constructRelativeCapturesDir(newProfile.getId(), dfendProfile.getConfFile().getParentFile(), dfendProfile.getSettings().detectDosboxVersionGeneration()); File dstCapAbsolute = FileUtils.canonicalToData(dstCap); FileUtils.createDir(dstCapAbsolute); FileUtils.copyFiles(new File(cap), dstCapAbsolute); dfendProfile.getSettings().setValue("dosbox", "captures", dstCapRelative); if (performCleanup) { dfendProfile.getSettings().removeSection("joystick"); dfendProfile.getSettings().removeSection("sdl"); } // The new profile is associated to the Default DOSBox version // However, the imported profile may be associated to another DB version // Therefore, update the settings to defaultDBVersion dfendProfile.alterToDosboxVersionGeneration(dfendProfile); dfendProfile.save(); newProfile = dbase.updateProfileConf(FileUtils.makeRelativeToData(dfendProfile.getConfFile()).getPath(), dstCap, newProfile.getId()); if (dfendProfile.getAutoexec().isIncomplete()) { ps.println(settings.msg("dialog.multiprofile.error.profileincomplete")); } }
From source file:org.dbgl.util.FileUtils.java
public static File[] findFileSequence(File f) { List<File> result = new ArrayList<File>(); result.add(f);/* w w w .j a v a2s .com*/ int i = 1; String name = FilenameUtils.removeExtension(f.getName()); String ext = FilenameUtils.getExtension(f.getName()); if (name.endsWith(String.valueOf(i))) { File dir = f.getParentFile(); if (dir != null) { File[] files = dir.listFiles(new FileFilter() { public boolean accept(File f) { return f.isFile(); } }); String[] fileNames = getNames(files); if (files != null) { int index; do { i++; String nextFileName = StringUtils.chop(name) + String.valueOf(i) + FilenameUtils.EXTENSION_SEPARATOR + ext; index = ArrayUtils.indexOf(fileNames, nextFileName); if (index >= 0) { result.add(files[index]); } } while (index >= 0); } } } return result.toArray(new File[0]); }