List of usage examples for org.apache.commons.io FilenameUtils getExtension
public static String getExtension(String filename)
From source file:abfab3d.io.input.STSReader.java
/** * Load a STS file into a grid./*from w ww.j av a 2 s.c om*/ * * @param file The zip file * @return * @throws java.io.IOException */ public TriangleMesh[] loadMeshes(String file) throws IOException { ZipFile zip = null; TriangleMesh[] ret_val = null; try { zip = new ZipFile(file); ZipEntry entry = zip.getEntry("manifest.xml"); if (entry == null) { throw new IOException("Cannot find manifest.xml in top level"); } InputStream is = zip.getInputStream(entry); mf = parseManifest(is); if (mf == null) { throw new IOException("Could not parse manifest file"); } List<STSPart> plist = mf.getParts(); int len = plist.size(); ret_val = new TriangleMesh[len]; for (int i = 0; i < len; i++) { STSPart part = plist.get(i); ZipEntry ze = zip.getEntry(part.getFile()); MeshReader reader = new MeshReader(zip.getInputStream(ze), "", FilenameUtils.getExtension(part.getFile())); IndexedTriangleSetBuilder its = new IndexedTriangleSetBuilder(); reader.getTriangles(its); // TODO: in this case we could return a less heavy triangle mesh struct? WingedEdgeTriangleMesh mesh = new WingedEdgeTriangleMesh(its.getVertices(), its.getFaces()); ret_val[i] = mesh; } return ret_val; } finally { if (zip != null) zip.close(); } }
From source file:com.banyou.backend.service.resource.ImageService.java
private String createRealPath(String fileName) { Calendar now = Calendar.getInstance(); String year = String.valueOf(now.get(Calendar.YEAR)); String month = String.valueOf(now.get(Calendar.MONTH) + 1); String day = String.valueOf(now.get(Calendar.DAY_OF_MONTH)); String pre = UUID.randomUUID().toString(); return separator + year + separator + month + separator + day + separator + pre + '.' + FilenameUtils.getExtension(fileName); }
From source file:com.qwazr.library.LibraryManagerImpl.java
@Override public void accept(TrackedInterface.ChangeReason changeReason, File jsonFile) { String extension = FilenameUtils.getExtension(jsonFile.getName()); if (!"json".equals(extension)) return;/*from www.j a v a2 s .c om*/ switch (changeReason) { case UPDATED: loadLibrarySet(jsonFile); break; case DELETED: unloadLibrarySet(jsonFile); break; } }
From source file:it.baywaylabs.jumpersumo.robot.ServerPolling.java
/** * This method is called when invoke <b>execute()</b>.<br /> * Do not invoke manually. Use: new ServerPolling().execute(url1, url2, url3); * * @param sUrl List of Url that will be download. * @return null if all is going ok.//from w w w. j av a 2s . c o m */ @Override protected String doInBackground(String... sUrl) { InputStream input = null; OutputStream output = null; File folder = new File(Constants.DIR_ROBOT); String baseName = FilenameUtils.getBaseName(sUrl[0]); String extension = FilenameUtils.getExtension(sUrl[0]); Log.d(TAG, "FileName: " + baseName + " - FileExt: " + extension); if (!folder.exists()) { folder.mkdir(); } HttpURLConnection connection = null; if (!f.isUrl(sUrl[0])) return "Url malformed!"; try { URL url = new URL(sUrl[0]); connection = (HttpURLConnection) url.openConnection(); connection.connect(); // expect HTTP 200 OK, so we don't mistakenly save error report // instead of the file if (!sUrl[0].endsWith(".csv") && connection.getResponseCode() != HttpURLConnection.HTTP_OK) { return "Server returned HTTP " + connection.getResponseCode() + " " + connection.getResponseMessage(); } // this will be useful to display download percentage // might be -1: server did not report the length int fileLength = connection.getContentLength(); // download the file input = connection.getInputStream(); output = new FileOutputStream(folder.getAbsolutePath() + "/" + baseName + "." + extension); byte data[] = new byte[4096]; long total = 0; int count; while ((count = input.read(data)) != -1) { // allow canceling with back button if (isCancelled()) { input.close(); return null; } total += count; // publishing the progress.... if (fileLength > 0) // only if total length is known publishProgress((int) (total * 100 / fileLength)); output.write(data, 0, count); } } catch (Exception e) { Log.e(TAG, e.getMessage()); return e.toString(); } finally { try { if (output != null) output.close(); if (input != null) input.close(); } catch (IOException ignored) { } if (connection != null) connection.disconnect(); } return null; }
From source file:bboss.org.artofsolving.jodconverter.OfficeDocumentConverter.java
public void convert(File inputFile, File outputFile, DocumentFormat outputFormat) throws OfficeException { String inputExtension = FilenameUtils.getExtension(inputFile.getName()); DocumentFormat inputFormat = formatRegistry.getFormatByExtension(inputExtension); StandardConversionTask conversionTask = new StandardConversionTask(inputFile, outputFile, outputFormat); conversionTask.setDefaultLoadProperties(defaultLoadProperties); conversionTask.setInputFormat(inputFormat); officeManager.execute(conversionTask); }
From source file:net.sourceforge.atunes.kernel.modules.repository.LocalAudioObjectValidator.java
@Override public boolean isOneOfTheseFormats(final ILocalAudioObject localAudioObject, final LocalAudioObjectFormat... formats) { if (localAudioObject == null) { return false; }//from ww w.j a va 2s . c om String extension = FilenameUtils.getExtension(this.fileManager.getFileName(localAudioObject)); for (LocalAudioObjectFormat format : formats) { if (extension.equalsIgnoreCase(format.getExtension())) { return true; } } return false; }
From source file:com.kamike.misc.FsNameUtils.java
public static String getName(String prefix, String disk, String name, String fid, String uid, Date date) { String extension = FilenameUtils.getExtension(name); //?/*from w ww. ja va 2 s . c o m*/ return getName(prefix, disk, getShortDate(date), name, fid, uid, extension); }
From source file:ch.entwine.weblounge.tools.importer.ResourceImporterCallback.java
/** * This method is called if a resource file has been found. * //from w w w.ja v a2 s . c om * @see ch.entwine.weblounge.tools.importer.AbstractImporterCallback#fileImported(java.io.File) */ public boolean fileImported(File f) { // load collection information File collXml = new File(FilenameUtils.getFullPath(f.getPath()) + "repository.xml"); if (!collXml.exists()) { System.err.println("No repository information (repository.xml) found for file: " + f.getName()); return false; } // path relative to the src directory String relpath = f.getPath().replaceAll(this.srcDir.getAbsolutePath(), ""); // Check if collXml contains information for this file XMLDocument repoXml = new XMLDocument(collXml); if (repoXml.getNode("/collection/entry[@id='" + relpath + "']") == null) return false; UUID uuid = UUID.randomUUID(); File resourceXml = null; ImageInfo imageInfo = null; try { // create temporary resource descriptor file resourceXml = File.createTempFile(uuid.toString(), ".xml"); // try loading file as image imageInfo = Sanselan.getImageInfo(f); } catch (IOException e) { System.err.println("Error processing file '" + relpath + "': " + e.getMessage()); return false; } catch (ImageReadException e) { // file is not an image } ImporterState.getInstance().putUUID(relpath, uuid); String filename = "de.".concat(FilenameUtils.getExtension(f.getName())); // check, if file is an image resource String subfolder = null; if (imageInfo != null) { subfolder = "images"; Source xsl = new StreamSource(this.getClass().getResourceAsStream("/xsl/convert-image.xsl")); // set the TransformFactory to use the Saxon TransformerFactoryImpl method System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); TransformerFactory transFact = TransformerFactory.newInstance(); Transformer trans; try { trans = transFact.newTransformer(xsl); trans.setParameter("fileid", relpath); trans.setParameter("uuid", uuid.toString()); trans.setParameter("path", relpath); trans.setParameter("imgwidth", imageInfo.getWidth()); trans.setParameter("imgheight", imageInfo.getHeight()); this.transformXml(collXml, resourceXml, trans); } catch (TransformerConfigurationException e) { System.err.println(e.getMessage()); return false; } } else { subfolder = "files"; Source xsl = new StreamSource(this.getClass().getResourceAsStream("/xsl/convert-file.xsl")); TransformerFactory transFact = TransformerFactory.newInstance(); Transformer trans; try { trans = transFact.newTransformer(xsl); trans.setParameter("fileid", relpath); trans.setParameter("uuid", uuid.toString()); trans.setParameter("path", relpath); this.transformXml(collXml, resourceXml, trans); } catch (TransformerConfigurationException e) { System.err.println(e.getMessage()); return false; } } this.storeFile(f, destDir, subfolder, filename, uuid, 0); this.storeFile(resourceXml, destDir, subfolder, "index.xml", uuid, 0); System.out.println("Imported resource " + f.getName()); return true; }
From source file:io.proleap.vb6.runner.impl.VbParseTestRunnerImpl.java
private boolean isClazzModule(final File inputFile) { final String extension = FilenameUtils.getExtension(inputFile.getName()); return "cls".equals(extension); }
From source file:com.opensearchserver.textextractor.test.AllTest.java
protected File getTempFile(String fileName) throws IOException { File tempFile = File.createTempFile("oss_text_extractor", "." + FilenameUtils.getExtension(fileName)); FileOutputStream fos = new FileOutputStream(tempFile); InputStream inputStream = getStream(fileName); IOUtils.copy(inputStream, fos);/* w ww . jav a 2s.co m*/ return tempFile; }