Example usage for java.io File getAbsoluteFile

List of usage examples for java.io File getAbsoluteFile

Introduction

In this page you can find the example usage for java.io File getAbsoluteFile.

Prototype

public File getAbsoluteFile() 

Source Link

Document

Returns the absolute form of this abstract pathname.

Usage

From source file:com.hightern.fckeditor.connector.impl.AbstractLocalFileSystemConnector.java

public String fileUpload(final ResourceType type, final String currentFolder, final String fileName,
        final InputStream inputStream) throws InvalidCurrentFolderException, WriteException {
    final String absolutePath = getRealUserFilesAbsolutePath(
            RequestCycleHandler.getUserFilesAbsolutePath(ThreadLocalData.getRequest()));
    final File typeDir = AbstractLocalFileSystemConnector.getOrCreateResourceTypeDir(absolutePath, type);
    final File currentDir = new File(typeDir, currentFolder);
    if (!currentDir.exists() || !currentDir.isDirectory()) {
        throw new InvalidCurrentFolderException();
    }/*from   www . j a v  a  2  s. c o  m*/

    final File newFile = new File(currentDir, fileName);
    final File fileToSave = UtilsFile.getUniqueFile(newFile.getAbsoluteFile());

    try {
        IOUtils.copyLarge(inputStream, new FileOutputStream(fileToSave));
    } catch (final IOException e) {
        throw new WriteException();
    }
    return fileToSave.getName();
}

From source file:com.safetys.framework.fckeditor.connector.impl.AbstractLocalFileSystemConnector.java

public String fileUpload(final ResourceType type, final String currentFolder, final String fileName,
        final InputStream inputStream) throws InvalidCurrentFolderException, WriteException {
    final String absolutePath = this.getRealUserFilesAbsolutePath(
            RequestCycleHandler.getUserFilesAbsolutePath(ThreadLocalData.getRequest()));
    final File typeDir = AbstractLocalFileSystemConnector.getOrCreateResourceTypeDir(absolutePath, type);
    final File currentDir = new File(typeDir, currentFolder);
    if (!currentDir.exists() || !currentDir.isDirectory()) {
        throw new InvalidCurrentFolderException();
    }//w ww.jav  a2s. c om

    final File newFile = new File(currentDir, fileName);
    final File fileToSave = UtilsFile.getUniqueFile(newFile.getAbsoluteFile());

    try {
        IOUtils.copyLarge(inputStream, new FileOutputStream(fileToSave));
    } catch (final IOException e) {
        throw new WriteException();
    }
    return fileToSave.getName();
}

From source file:net.fckeditor.connector.impl.AbstractLocalFileSystemConnector.java

public String fileUpload(final ResourceType type, final String currentFolder, final String fileName,
        final InputStream inputStream) throws InvalidCurrentFolderException, WriteException {
    String absolutePath = getRealUserFilesAbsolutePath(
            RequestCycleHandler.getUserFilesAbsolutePath(ThreadLocalData.getRequest()));
    File typeDir = getOrCreateResourceTypeDir(absolutePath, type);
    File currentDir = new File(typeDir, currentFolder);
    if (!currentDir.exists() || !currentDir.isDirectory())
        throw new InvalidCurrentFolderException();

    File newFile = new File(currentDir, fileName);
    File fileToSave = UtilsFile.getUniqueFile(newFile.getAbsoluteFile());

    try {//  www  .  j  a  va 2 s.co  m
        IOUtils.copyLarge(inputStream, new FileOutputStream(fileToSave));
    } catch (IOException e) {
        throw new WriteException();
    }
    return fileToSave.getName();
}

From source file:org.mitre.jdbc.datasource.util.SqlFileParser.java

private void processFile(File file, StringBuilder sql) throws IOException {
    BufferedReader fileReader = new BufferedReader(new FileReader(file.getAbsoluteFile()));
    String line = null;/*from   w  ww  . ja  v a 2 s .  co m*/
    while ((line = fileReader.readLine()) != null) {
        processLine(sql, line);
    }
}

From source file:de.rub.syssec.saaf.analysis.steps.reporting.STReportGenerator.java

private void ensureDestinationPath(File path) throws ReportingException {
    File parent = path.getAbsoluteFile().getParentFile();
    if (!parent.exists()) {
        parent.mkdirs();/*  w w w .  j a  v a  2 s  .  c o  m*/
    }
}

From source file:com.cedarsoft.io.LinkUtils.java

/**
 * Checks whether a given file is a symbolic link.
 *
 * @param file the file/*from www  .  ja  v a2  s .c om*/
 * @return whether the given file is a symbolic link
 *
 * @throws IOException if any.
 */
public boolean isSymbolicLink(@Nonnull File file) throws IOException {
    return !file.getAbsoluteFile().equals(file.getCanonicalFile());
}

From source file:com.moss.veracity.core.config.ConfigManager.java

public ConfigManager(File file) {

    if (file == null) {
        throw new NullPointerException();
    }//from w w  w .  j  av a2  s. c  o  m

    this.file = file.getAbsoluteFile();

    try {
        jaxbContext = JAXBContext.newInstance(Configuration.class);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    try {
        current = read();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    monitor = FileMonitor.monitor(file, 1000);
    monitor.addListener(new ConfigFileListener());
}

From source file:com.quinsoft.zeidon.standardoe.ActivateOiFromFileDb.java

/**
 * Activates each of the files in the directory that have the same LodDef until if
 * finds the right one.//from w w w  . java  2  s  . c  o m
 *
 * @return
 */
private View performScan() {
    task.dblog().debug("FileDB: performing scan of %s", fileDbUtils.getDirectoryName());
    File dir = new File(fileDbUtils.getDirectoryName());
    FileFilter fileFilter = new WildcardFileFilter(
            lodDef.getName() + "*" + fileDbUtils.getStreamFormat().getExtension());
    File[] files = dir.listFiles(fileFilter);
    for (File file : files) {
        task.dblog().debug("Loading %s and checking for match", file.getAbsoluteFile());
        View v = activateFile(file.getAbsolutePath());
        if (v.cursor(lodDef.getRoot()).setFirst(qualAttributeDef, qualValue) == CursorResult.SET) {
            task.dblog().debug("Got a match!");
            return v;
        }
    }

    // We didn't find a match so return the original empty view.
    return view;
}

From source file:pzalejko.iot.hardware.home.core.service.configuration.DefaultConfigurationService.java

@PostConstruct
public void init() {
    final String property = System.getProperty(CONFIGURATION_DIRECTORY_KEY);
    if (property == null) {
        final String msg = MessageFormat.format(LogMessages.CONFIGURATION_DIRECTORY_HAS_NOT_BE_SPECIFIED,
                CONFIGURATION_DIRECTORY_KEY);
        throw new IllegalStateException(msg);
    }/*from   www.  jav  a  2  s.  co m*/

    final File file = new File(property);
    if (file.isDirectory()) {
        this.confDirectory = file;
        LOG.debug(LogMessages.FOUND_CONFIGURATION_DIRECTORY, file.getAbsoluteFile());
    } else {
        final String msg = MessageFormat.format(LogMessages.PROPERTY_DOES_NOT_POINT_TO_ANY_DIRECTORY,
                CONFIGURATION_DIRECTORY_KEY);
        throw new IllegalStateException(msg);
    }
}

From source file:com.simpligility.maven.provisioner.MavenRepositoryHelper.java

public void deployToRemote(String targetUrl, String username, String password) {
    // Using commons-io, if performance or so is a problem it might be worth looking at the Java 8 streams API
    // e.g. http://blog.jooq.org/2014/01/24/java-8-friday-goodies-the-new-new-io-apis/
    // not yet though..
    Collection<File> subDirectories = FileUtils.listFilesAndDirs(repositoryPath,
            (IOFileFilter) DirectoryFileFilter.DIRECTORY, TrueFileFilter.INSTANCE);
    Collection<File> leafDirectories = new ArrayList<File>();
    for (File subDirectory : subDirectories) {
        if (isLeafVersionDirectory(subDirectory)) {

            leafDirectories.add(subDirectory);
        }//from w  w w. j  a  va2s. c o  m
    }
    for (File leafDirectory : leafDirectories) {
        String leafAbsolutePath = leafDirectory.getAbsoluteFile().toString();
        int repoAbsolutePathLength = repositoryPath.getAbsoluteFile().toString().length();
        String leafRepoPath = leafAbsolutePath.substring(repoAbsolutePathLength + 1, leafAbsolutePath.length());

        Gav gav = GavUtil.getGavFromRepositoryPath(leafRepoPath);

        // only interested in files using the artifactId-version* pattern
        // don't bother with .sha1 files
        IOFileFilter fileFilter = new AndFileFilter(
                new WildcardFileFilter(gav.getArtifactId() + "-" + gav.getVersion() + "*"),
                new NotFileFilter(new SuffixFileFilter("sha1")));
        Collection<File> artifacts = FileUtils.listFiles(leafDirectory, fileFilter, null);

        Authentication auth = new AuthenticationBuilder().addUsername(username).addPassword(password).build();

        RemoteRepository distRepo = new RemoteRepository.Builder("repositoryIdentifier", "default", targetUrl)
                .setAuthentication(auth).build();

        DeployRequest deployRequest = new DeployRequest();
        deployRequest.setRepository(distRepo);
        for (File file : artifacts) {
            String extension;
            if (file.getName().endsWith("tar.gz")) {
                extension = "tar.gz";
            } else {
                extension = FilenameUtils.getExtension(file.getName());
            }

            String baseFileName = gav.getFilenameStart() + "." + extension;
            String fileName = file.getName();
            String g = gav.getGroupdId();
            String a = gav.getArtifactId();
            String v = gav.getVersion();

            Artifact artifact = null;
            if (gav.getPomFilename().equals(fileName)) {
                artifact = new DefaultArtifact(g, a, "pom", v);
            } else if (gav.getJarFilename().equals(fileName)) {
                artifact = new DefaultArtifact(g, a, "jar", v);
            } else if (gav.getSourceFilename().equals(fileName)) {
                artifact = new DefaultArtifact(g, a, "sources", "jar", v);
            } else if (gav.getJavadocFilename().equals(fileName)) {
                artifact = new DefaultArtifact(g, a, "javadoc", "jar", v);
            } else if (baseFileName.equals(fileName)) {
                artifact = new DefaultArtifact(g, a, extension, v);
            } else {
                String classifier = file.getName().substring(gav.getFilenameStart().length() + 1,
                        file.getName().length() - ("." + extension).length());
                artifact = new DefaultArtifact(g, a, classifier, extension, v);
            }

            if (artifact != null) {
                artifact = artifact.setFile(file);
                deployRequest.addArtifact(artifact);
            }

        }

        try {
            system.deploy(session, deployRequest);
        } catch (Exception e) {
            logger.info("Deployment failed with " + e.getMessage() + ", artifact might be deployed already.");
        }
    }
}