List of usage examples for java.io File isAbsolute
public boolean isAbsolute()
From source file:com.npower.dm.setup.task.ManufacturerTask.java
@Override protected void process() throws SetupException { List<String> filenames = this.getFilenames(); ManagementBeanFactory factory = null; try {/*from w w w . jav a 2s.com*/ factory = this.getManagementBeanFactory(); ModelBean modelBean = factory.createModelBean(); factory.beginTransaction(); for (String filename : filenames) { // Process the file, and import data into database. File file = new File(filename); if (!file.isAbsolute()) { file = new File(this.getSetup().getWorkDir(), filename); } List<ManufacturerItem> items = this.loadManufacturerItems(file.getAbsolutePath()); for (ManufacturerItem item : items) { Manufacturer manufacturer = modelBean.getManufacturerByExternalID(item.getExternalID()); if (manufacturer == null) { // Create a new manufacturer. manufacturer = modelBean.newManufacturerInstance(); log.info("Create a new manufacturer: " + item.getExternalID()); } else { log.info("Modify a manufacturer: " + item.getExternalID()); } this.copy(item, manufacturer); modelBean.update(manufacturer); } } factory.commit(); } catch (Exception ex) { if (factory != null) { factory.rollback(); } throw new SetupException("Error in import manufacturers.", ex); } finally { if (factory != null) { factory.release(); } } }
From source file:com.pablissimo.sonar.LCOVParserImpl.java
/** * Returns a java.io.File for the given path. * If path is not absolute, returns a File with module base directory as parent path. *///w w w .j av a 2 s .c o m protected File getIOFile(File baseDir, String path) { File file = new File(path); if (!file.isAbsolute()) { file = new File(baseDir, path); } return file; }
From source file:com.pablissimo.sonar.TsCoverageSensor.java
/** * Returns a java.io.File for the given path. * If path is not absolute, returns a File with module base directory as parent path. *//*from ww w . j a va 2s . c o m*/ public File getIOFile(File baseDir, String path) { File file = new File(path); if (!file.isAbsolute()) { file = new File(baseDir, path); } return file; }
From source file:org.dbgl.util.FileUtils.java
public static File prefixAndSanitizeToDosroot(final File basePath, final File file) { if (!file.isAbsolute()) return makeRelativeToDosroot(canonicalToDosroot(new File(basePath, file.getPath()).getPath())); return file;//from ww w . ja v a 2 s. co m }
From source file:org.eclipse.equinox.http.servlet.internal.multipart.MultipartSupportImpl.java
public MultipartSupportImpl(ExtendedServletDTO servletDTO, ServletContext servletContext) { this.servletDTO = servletDTO; // Must return non-null File. See Servlet 3.1 4.8.1 File baseStorage = (File) servletContext.getAttribute(ServletContext.TEMPDIR); if (servletDTO.multipartLocation.length() > 0) { File storage = new File(servletDTO.multipartLocation); if (!storage.isAbsolute()) { storage = new File(baseStorage, storage.getPath()); }/* w w w . j a va 2 s. c o m*/ baseStorage = storage; } checkPermission(baseStorage, servletContext); baseStorage.mkdirs(); DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setRepository(baseStorage); if (servletDTO.multipartFileSizeThreshold > 0) { factory.setSizeThreshold(servletDTO.multipartFileSizeThreshold); } upload = new ServletFileUpload(factory); if (servletDTO.multipartMaxFileSize > -1L) { upload.setFileSizeMax(servletDTO.multipartMaxFileSize); } if (servletDTO.multipartMaxRequestSize > -1L) { upload.setSizeMax(servletDTO.multipartMaxRequestSize); } }
From source file:cppsensor.sonar.CppProjectAnalysisHandler.java
private void getPathsFromSetting(Settings settings, String key, List<String> results) { String[] paths = settings.getStringArray(key); for (String path : paths) { String value = CppGeneralSettings.resolveValue(settings, path); if (value != null) { File f = new File(value); if (!f.isAbsolute()) { f = new File(baseDir, value); }// w ww.j ava 2s .c om results.add(f.getPath()); log.info(String.format("From %s added %s", key, path)); } } }
From source file:io.neba.core.logviewer.LogFiles.java
private File getConfiguredLogfile(Configuration logConfiguration) throws IOException { Dictionary properties = logConfiguration.getProperties(); if (properties == null) { return null; }// w w w.j av a2 s .c o m String logFilePath = (String) properties.get(LOG_FILE_PROPERTY); if (isEmpty(logFilePath)) { return null; } File logFile = new File(logFilePath); if (!logFile.isAbsolute()) { logFile = new File(this.slingHomeDirectory, logFilePath); } return logFile.getCanonicalFile(); }
From source file:com.photon.maven.plugins.android.standalonemojos.MojoProjectStub.java
/** * Normalize a path./*from w w w . j ava 2 s . c om*/ * <p> * Ensure path is absolute, and has proper system file separators. * * @param path the raw path. * @return */ private File normalize(final String path) { String ospath = FilenameUtils.separatorsToSystem(path); File file = new File(ospath); if (file.isAbsolute()) { return file; } else { return new File(getBasedir(), ospath); } }
From source file:com.mgmtp.perfload.perfalyzer.normalization.Normalizer.java
public void normalize(final File file) throws IOException { checkState(!file.isAbsolute(), "'file' must be relative"); String filePath = file.getPath(); String[] pathElements = split(getPath(filePath), SystemUtils.FILE_SEPARATOR); // strip out dir StrBuilder sb = new StrBuilder(); for (int i = 0; i < pathElements.length; ++i) { if (i == 1) { continue; // strip out dir, e. g. perfmon-logs, measuring-logs }//from ww w .ja v a 2s. c o m sb.appendSeparator(SystemUtils.FILE_SEPARATOR); sb.append(pathElements[i]); } String dirPath = sb.toString(); Map<String, FileChannel> channels = newHashMap(); List<OutputStream> outputStreams = newArrayList(); FileInputStream fis = null; try { fis = new FileInputStream(new File(sourceDir, filePath)); //relative to source dir for (Scanner scanner = new Scanner(fis.getChannel(), Charsets.UTF_8.name()); scanner.hasNext();) { String line = scanner.nextLine(); if (trimToNull(line) == null || line.startsWith("#")) { continue; } List<ChannelData> channelDataList = normalizingStrategy.normalizeLine(line); for (ChannelData channelData : channelDataList) { FileChannel channel = channels.get(channelData.getChannelKey()); if (channel == null) { String baseName = channelData.getChannelBaseName(); String key = channelData.getChannelKey(); String fileName = new File(dirPath, String.format("[%s][%s].csv", baseName, key)).getPath(); File destFile = new File(destDir, fileName); destFile.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(destFile); outputStreams.add(fos); channel = fos.getChannel(); channels.put(channelData.getChannelKey(), channel); } writeLineToChannel(channel, channelData.getValue(), Charsets.UTF_8); } } } finally { outputStreams.forEach(IOUtils::closeQuietly); closeQuietly(fis); } }
From source file:org.apache.maven.scm.provider.svn.svnjava.command.checkin.SvnJavaCheckInCommand.java
/** * {@inheritDoc}/*from w ww. j a v a2 s . c o m*/ */ protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, ScmVersion tag) throws ScmException { if (getLogger().isInfoEnabled()) { getLogger().info("SVN commit directory: " + fileSet.getBasedir().getAbsolutePath()); } SvnJavaScmProviderRepository javaRepo = (SvnJavaScmProviderRepository) repo; CommitHandler handler = new CommitHandler(fileSet.getBasedir().getAbsolutePath()); SVNCommitClient svnCommitClient = javaRepo.getClientManager().getCommitClient(); svnCommitClient.setCommitHandler(handler); try { List<File> tmpPaths = fileSet.getFileList(); List<File> paths; if (tmpPaths == null || tmpPaths.isEmpty()) { paths = new ArrayList<File>(1); paths.add(fileSet.getBasedir()); } else { paths = new ArrayList<File>(tmpPaths.size()); for (File f : tmpPaths) { if (f.isAbsolute()) { paths.add(f); } else { paths.add(new File(fileSet.getBasedir(), f.toString())); } } } SVNCommitInfo svnCommitInfo = SvnJavaUtil.commit(svnCommitClient, paths.toArray(new File[paths.size()]), false, message, true); List<ScmFile> files = new ArrayList<ScmFile>(); for (String filePath : handler.getFiles()) { files.add(new ScmFile(filePath, ScmFileStatus.CHECKED_IN)); } return new CheckInScmResult(SvnJavaScmProvider.COMMAND_LINE, files, Long.toString(svnCommitInfo.getNewRevision())); } catch (SVNException e) { return new CheckInScmResult(SvnJavaScmProvider.COMMAND_LINE, "SVN commit failed.", e.getMessage(), false); } finally { javaRepo.getClientManager().getCommitClient().setEventHandler(null); } }