List of usage examples for java.io File isAbsolute
public boolean isAbsolute()
From source file:org.apache.solr.handler.dataimport.TikaEntityProcessor.java
@Override protected void firstInit(Context context) { super.firstInit(context); try {/*from www. j av a2s. c o m*/ String tikaConfigFile = context.getResolvedEntityAttribute("tikaConfig"); if (tikaConfigFile == null) { ClassLoader classLoader = context.getSolrCore().getResourceLoader().getClassLoader(); tikaConfig = new TikaConfig(classLoader); } else { File configFile = new File(tikaConfigFile); if (!configFile.isAbsolute()) { configFile = new File(context.getSolrCore().getResourceLoader().getConfigDir(), tikaConfigFile); } tikaConfig = new TikaConfig(configFile); } } catch (Exception e) { wrapAndThrow(SEVERE, e, "Unable to load Tika Config"); } String extractEmbeddedString = context.getResolvedEntityAttribute("extractEmbedded"); if ("true".equals(extractEmbeddedString)) { extractEmbedded = true; } format = context.getResolvedEntityAttribute("format"); if (format == null) format = "text"; if (!"html".equals(format) && !"xml".equals(format) && !"text".equals(format) && !"none".equals(format)) throw new DataImportHandlerException(SEVERE, "'format' can be one of text|html|xml|none"); htmlMapper = context.getResolvedEntityAttribute("htmlMapper"); if (htmlMapper == null) htmlMapper = "default"; if (!"default".equals(htmlMapper) && !"identity".equals(htmlMapper)) throw new DataImportHandlerException(SEVERE, "'htmlMapper', if present, must be 'default' or 'identity'"); parser = context.getResolvedEntityAttribute("parser"); if (parser == null) { parser = AUTO_PARSER; } spatialMetadataField = context.getResolvedEntityAttribute("spatialMetadataField"); }
From source file:com.redhat.rcm.maven.plugin.buildmetadata.io.AdditionalLocationsSupport.java
private void addFileToSources(final File propertiesFile, final String targetLocation, final boolean attach) throws MojoExecutionException { final File testFile = new File(targetLocation); final File targetLocationDir; final File generatedSourcesMetaInfDir; if (testFile.isAbsolute()) { targetLocationDir = null;/*w ww . ja v a 2 s. c om*/ generatedSourcesMetaInfDir = testFile; } else { targetLocationDir = new File(project.getBuild().getDirectory(), targetLocation); generatedSourcesMetaInfDir = new File(targetLocationDir, "META-INF"); } MojoFileUtils.ensureExists(generatedSourcesMetaInfDir); try { final File propertiesFileInSources = new File(generatedSourcesMetaInfDir, propertiesFile.getName()); FileUtils.copyFile(propertiesFile, propertiesFileInSources); if (attach && targetLocationDir != null) { project.addCompileSourceRoot(targetLocationDir.getAbsolutePath()); } } catch (final IOException e) { throw new MojoExecutionException("Cannot copy properties to generated sources.", e); } }
From source file:org.apache.jmeter.protocol.http.control.AuthManager.java
/** * Save the authentication data to a file. *//*from www. ja v a 2 s .c om*/ public void save(String authFile) throws IOException { File file = new File(authFile); if (!file.isAbsolute()) { file = new File(System.getProperty("user.dir"), authFile); } PrintWriter writer = new PrintWriter(new FileWriter(file)); writer.println("# JMeter generated Authorization file"); for (int i = 0; i < getAuthObjects().size(); i++) { Authorization auth = (Authorization) getAuthObjects().get(i).getObjectValue(); writer.println(auth.toString()); } writer.flush(); writer.close(); }
From source file:oracle.kv.hadoop.table.TableInputFormatBase.java
/** * Set/create the artifacts required to connect to and interact * with a secure store; specifically, a login properties file, * a trust file containing public keys and/or certificates, and * <code>PasswordCredentials</code>. If the value input for the * <code>loginFile</code> and <code>trustFile</code> parameter * is a fully-qualified path, then this method initializes the * corresponding static variables to those values so that the * <code>getSplits</code> method can contact a secure store, extracts * the filenames from those paths, uses those values to initialize * the corresponding static filename variables used to initialize * the splits that are created, and returns. * <p>//from w ww . j av a2s. c o m * If the value input for the <code>loginFile</code> and * <code>trustFile</code> parameter is not a fully-qualified path, * then this method uses the given file names to retrieve the contents * of the associated login file and trust file as resources from * the classpath, and writes that information to corresponding files * on the local file system (in a directory owned by the user under * which the application is executed). After generating the local * files, the fully-qualified paths to those files are used to * initialize the corresponding static variables so that the * <code>getSplits</code> method can contact a secure store. */ private static void setLocalKVSecurity(final String loginFile, final PasswordCredentials userPasswordCredentials, final String trustFile) throws IOException { if (loginFile == null) { return; } if (userPasswordCredentials == null) { return; } if (trustFile == null) { return; } final File loginFd = new File(loginFile); boolean loginIsAbsolute = false; if (loginFd.isAbsolute()) { loginIsAbsolute = true; TableInputFormatBase.localLoginFile = loginFile; TableInputFormatBase.loginFlnm = loginFd.getName(); } else { TableInputFormatBase.loginFlnm = loginFile; } TableInputFormatBase.passwordCredentials = userPasswordCredentials; final File trustFd = new File(trustFile); boolean trustIsAbsolute = false; if (trustFd.isAbsolute()) { trustIsAbsolute = true; TableInputFormatBase.trustFlnm = trustFd.getName(); } else { TableInputFormatBase.trustFlnm = trustFile; } if (loginIsAbsolute && trustIsAbsolute) { return; } /* * If loginFile and/or trustFile is a filename and not an absolute * path, then generate local versions of the file. */ final File userSecurityDirFd = new File(USER_SECURITY_DIR); if (!userSecurityDirFd.exists()) { if (!userSecurityDirFd.mkdirs()) { throw new IOException("failed to create " + userSecurityDirFd); } } final ClassLoader cl = TableInputFormatBase.class.getClassLoader(); if (!loginIsAbsolute) { InputStream loginStream = null; if (cl != null) { loginStream = cl.getResourceAsStream(loginFlnm); } else { loginStream = ClassLoader.getSystemResourceAsStream(loginFlnm); } /* * Retrieve the login configuration as a resource from the * classpath, and write that information to the user's local * file system. But exclude any properties related to user * authorization; that is, exclude all properties of the form * 'oracle.kv.auth.*", to prevent those property values from * being sent and cached on the DataNodes. */ final Properties loginProps = new Properties(); if (loginStream != null) { loginProps.load(loginStream); } /* Exclude 'oracle.kv.auth.*" properties. */ loginProps.remove(KVSecurityConstants.AUTH_USERNAME_PROPERTY); loginProps.remove(KVSecurityConstants.AUTH_WALLET_PROPERTY); loginProps.remove(KVSecurityConstants.AUTH_PWDFILE_PROPERTY); /* Strip off the path of the trust file. */ final String trustProp = loginProps.getProperty(KVSecurityConstants.SSL_TRUSTSTORE_FILE_PROPERTY); if (trustProp != null) { final File trustPropFd = new File(trustProp); if (!trustPropFd.exists()) { loginProps.setProperty(KVSecurityConstants.SSL_TRUSTSTORE_FILE_PROPERTY, trustPropFd.getName()); } } final File absoluteLoginFd = new File(USER_SECURITY_DIR + FILE_SEP + loginFlnm); final FileOutputStream loginFos = new FileOutputStream(absoluteLoginFd); try { loginProps.store(loginFos, null); } finally { loginFos.close(); } TableInputFormatBase.localLoginFile = absoluteLoginFd.toString(); } if (!trustIsAbsolute) { InputStream trustStream = null; if (cl != null) { trustStream = cl.getResourceAsStream(trustFlnm); } else { trustStream = ClassLoader.getSystemResourceAsStream(trustFlnm); } /* * Retrieve the trust credentials as a resource from the classpath, * and write that information to the user's local file system. */ final File absoluteTrustFd = new File(USER_SECURITY_DIR + FILE_SEP + trustFlnm); final FileOutputStream trustFlnmFos = new FileOutputStream(absoluteTrustFd); try { int nextByte = trustStream.read(); while (nextByte != -1) { trustFlnmFos.write(nextByte); nextByte = trustStream.read(); } } finally { trustFlnmFos.close(); } } }
From source file:org.apache.solr.handler.dataimport.CustomTikaEntityProcessor.java
@Override protected void firstInit(Context context) { try {/*from w ww . j av a 2 s . c o m*/ String tikaConfigFile = context.getResolvedEntityAttribute("tikaConfig"); if (tikaConfigFile == null) { ClassLoader classLoader = context.getSolrCore().getResourceLoader().getClassLoader(); tikaConfig = new TikaConfig(classLoader); } else { File configFile = new File(tikaConfigFile); if (!configFile.isAbsolute()) { configFile = new File(context.getSolrCore().getResourceLoader().getConfigDir(), tikaConfigFile); } tikaConfig = new TikaConfig(configFile); } } catch (Exception e) { wrapAndThrow(SEVERE, e, "Unable to load Tika Config"); } format = context.getResolvedEntityAttribute("format"); if (format == null) format = "text"; if (!"html".equals(format) && !"xml".equals(format) && !"text".equals(format) && !"none".equals(format)) throw new DataImportHandlerException(SEVERE, "'format' can be one of text|html|xml|none"); htmlMapper = context.getResolvedEntityAttribute("htmlMapper"); if (htmlMapper == null) htmlMapper = "default"; if (!"default".equals(htmlMapper) && !"identity".equals(htmlMapper)) throw new DataImportHandlerException(SEVERE, "'htmlMapper', if present, must be 'default' or 'identity'"); parser = context.getResolvedEntityAttribute("parser"); if (parser == null) { parser = AUTO_PARSER; } done = false; }
From source file:org.apache.nutch.plugin.PluginManifestParser.java
/** * Return the named plugin folder. If the name is absolute then it is * returned. Otherwise, for relative names, the classpath is scanned. *//*from w w w . j a va 2s.c om*/ public File getPluginFolder(String name) { File directory = new File(name); if (!directory.isAbsolute()) { URL url = PluginManifestParser.class.getClassLoader().getResource(name); if (url == null && directory.exists() && directory.isDirectory() && directory.listFiles().length > 0) { return directory; // relative path that is not in the classpath } else if (url == null) { LOG.warn("Plugins: directory not found: " + name); return null; } else if (!"file".equals(url.getProtocol())) { LOG.warn("Plugins: not a file: url. Can't load plugins from: " + url); return null; } String path = url.getPath(); if (WINDOWS && path.startsWith("/")) // patch a windows bug path = path.substring(1); try { path = URLDecoder.decode(path, "UTF-8"); // decode the url path } catch (UnsupportedEncodingException e) { } directory = new File(path); } return directory; }
From source file:com.streamsets.pipeline.stage.processor.tensorflow.TensorFlowProcessor.java
@Override protected List<ConfigIssue> init() { List<ConfigIssue> issues = super.init(); String[] modelTags = new String[conf.modelTags.size()]; modelTags = conf.modelTags.toArray(modelTags); if (Strings.isNullOrEmpty(conf.modelPath)) { issues.add(getContext().createConfigIssue(Groups.TENSOR_FLOW.name(), TensorFlowConfigBean.MODEL_PATH_CONFIG, Errors.TENSOR_FLOW_01)); return issues; }/*from w ww .ja v a 2 s. co m*/ try { File exportedModelDir = new File(conf.modelPath); if (!exportedModelDir.isAbsolute()) { exportedModelDir = new File(getContext().getResourcesDirectory(), conf.modelPath).getAbsoluteFile(); } this.savedModel = SavedModelBundle.load(exportedModelDir.getAbsolutePath(), modelTags); } catch (TensorFlowException ex) { issues.add(getContext().createConfigIssue(Groups.TENSOR_FLOW.name(), TensorFlowConfigBean.MODEL_PATH_CONFIG, Errors.TENSOR_FLOW_02, ex)); return issues; } this.session = this.savedModel.session(); this.conf.inputConfigs.forEach(inputConfig -> { Pair<String, Integer> key = Pair.of(inputConfig.operation, inputConfig.index); inputConfigMap.put(key, inputConfig); }); errorRecordHandler = new DefaultErrorRecordHandler(getContext()); return issues; }
From source file:com.npower.unicom.sync.AbstractImportDaemonPlugIn.java
public synchronized void run() { if (this.isRunning) { return;//w w w. jav a2s .c o m } this.isRunning = true; try { File dir = new File(this.getDirectory()); if (!dir.isAbsolute()) { dir = new File(System.getProperty("otas.dm.home"), this.getDirectory() + "/request"); } while (true) { try { File[] files = dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { if (StringUtils.isNotEmpty(name)) { if (name.toLowerCase().endsWith(".req")) { return true; } } return false; } }); if (files != null && files.length > 0) { // for (File file : files) { // File finishedDir = new File(file.getParentFile().getParentFile().getAbsolutePath(), "finished"); if (!finishedDir.exists()) { finishedDir.mkdirs(); } File finishedFile = new File(finishedDir, file.getName()); if (!finishedFile.exists()) { log.info("start processing new file: " + file.getAbsolutePath()); SyncProcessor processor = this.getProcessor(file); processor.sync(); log.info("end of processing new file: " + file.getAbsolutePath()); } else { log.info("discard finished file: " + file.getAbsolutePath()); finishedFile = new File(finishedDir, file.getName() + "." + System.currentTimeMillis()); } // boolean renameSuccess = file.renameTo(finishedFile); log.info("rename file:" + renameSuccess + " to " + finishedFile.getAbsolutePath()); } } } catch (Exception ex) { log.error("Error to monitor directory: " + this.getDirectory(), ex); } finally { try { Thread.sleep(this.getIntervalInSeconds() * 1000); } catch (InterruptedException e) { log.warn("File monitor thread has been interrupted: " + this.getDirectory()); if (log.isDebugEnabled()) { log.debug("File monitor thread has been interrupted: " + this.getDirectory(), e); } break; } } } } catch (Exception e) { log.error("Error to monitor directory: " + this.getDirectory(), e); } finally { this.isRunning = false; } }
From source file:at.gv.egiz.pdfas.moa.MOAConnector.java
private void init(Configuration config) throws CertificateException, FileNotFoundException, IOException { // Load certificate if not set otherwise if (this.certificate == null) { if (config.getValue(MOA_SIGN_CERTIFICATE) == null) { logger.error(MOA_SIGN_CERTIFICATE + " not configured for MOA connector"); throw new PdfAsWrappedIOException( new PdfAsException("Please configure: " + MOA_SIGN_CERTIFICATE + " to use MOA connector")); }/* w ww. j a v a 2s .co m*/ if (!(config instanceof ISettings)) { logger.error("Configuration is no instance of ISettings"); throw new PdfAsWrappedIOException(new PdfAsException("Configuration is no instance of ISettings")); } ISettings settings = (ISettings) config; String certificateValue = config.getValue(MOA_SIGN_CERTIFICATE); if (certificateValue.startsWith("http")) { logger.info("Loading certificate from url: " + certificateValue); try { URL certificateURL = new URL(certificateValue); this.certificate = new X509Certificate(certificateURL.openStream()); } catch (MalformedURLException e) { logger.error(certificateValue + " is not a valid url but starts with http!"); throw new PdfAsWrappedIOException( new PdfAsException(certificateValue + " is not a valid url but!")); } } else { File certFile = new File(certificateValue); if (!certFile.isAbsolute()) { certificateValue = settings.getWorkingDirectory() + "/" + config.getValue(MOA_SIGN_CERTIFICATE); certFile = new File(certificateValue); } logger.info("Loading certificate from file: " + certificateValue); this.certificate = new X509Certificate(new FileInputStream(certFile)); } } this.moaEndpoint = config.getValue(MOA_SIGN_URL); this.keyIdentifier = config.getValue(MOA_SIGN_KEY_ID); }
From source file:com.basistech.m2e.code.quality.pmd.MavenPluginConfigurationTranslator.java
private List<File> transformResourceStringsToFiles(final List<String> srcDirNames) { final File basedir = this.mavenProject.getBasedir(); final List<File> sourceDirectories = new ArrayList<File>(); if (srcDirNames != null) { for (String srcDirName : srcDirNames) { File srcDir = new File(srcDirName); if (!srcDir.isAbsolute()) { srcDir = new File(basedir, srcDir.getPath()); }/*from w ww. j a v a 2 s . c o m*/ sourceDirectories.add(srcDir); } } return sourceDirectories; }