Example usage for java.io File toURI

List of usage examples for java.io File toURI

Introduction

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

Prototype

public URI toURI() 

Source Link

Document

Constructs a file: URI that represents this abstract pathname.

Usage

From source file:com.stehno.sanctuary.core.remote.FileSystemRemoteStore.java

private FileObject findRemoteFile(File rootDirectory, File file) throws FileSystemException {
    final String localRoot = rootDirectory.toURI().toString();
    final String localFile = file.toURI().toString();
    final String relativePath = localFile.replace(localRoot, "");

    return remoteRoot.resolveFile(relativePath);
}

From source file:coria2015.server.ContentServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final URL url;
    IMAGE_URI = "/recipe/image/";
    if (request.getRequestURI().startsWith(IMAGE_URI)) {

        String recipeName = URLDecoder.decode(request.getRequestURI().substring(IMAGE_URI.length()), "UTF-8")
                .replace(" ", "-");
        String name = recipeImages.get(recipeName);
        File file = new File(imagePath, name);
        url = file.toURI().toURL();
    } else {/* w w  w  .j a  va  2 s .  com*/
        url = ContentServlet.class.getResource(format("/web%s", request.getRequestURI()));
    }

    if (url != null) {
        FileSystemManager fsManager = VFS.getManager();
        FileObject file = fsManager.resolveFile(url.toExternalForm());
        if (file.getType() == FileType.FOLDER) {
            response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
            response.setHeader("Location", format("%sindex.html", request.getRequestURI()));
            return;
        }

        String filename = url.getFile();
        if (filename.endsWith(".html"))
            response.setContentType("text/html");
        else if (filename.endsWith(".png"))
            response.setContentType("image/png");
        else if (filename.endsWith(".css"))
            response.setContentType("text/css");
        response.setStatus(HttpServletResponse.SC_OK);

        final ServletOutputStream out = response.getOutputStream();
        InputStream in = url.openStream();
        byte[] buffer = new byte[8192];
        int read;
        while ((read = in.read(buffer)) > 0) {
            out.write(buffer, 0, read);
        }
        out.flush();
        in.close();
        return;
    }

    // Not found
    error404(request, response);

}

From source file:de.qucosa.webapi.v1.FileHandlingService.java

public URI copyTempfileToTargetFileSpace(String tempFilename, String targetName, String qid)
        throws URISyntaxException, IOException {
    File sourceFile = new File(tempfilesPath, tempFilename);
    File targetFile = new File(new File(documentsPath, qid), targetName);
    FileUtils.copyFile(sourceFile, targetFile);
    return targetFile.toURI().normalize();
}

From source file:com.github.fge.jsonschema.main.cli.Main.java

private RetCode doValidation(final Reporter reporter, final List<File> files)
        throws IOException, ProcessingException {
    final File schemaFile = files.remove(0);
    final String uri = schemaFile.toURI().normalize().toString();
    JsonNode node;//from  w  w  w  .j  a  va  2 s  . co  m

    node = MAPPER.readTree(schemaFile);
    if (!syntaxValidator.schemaIsValid(node)) {
        System.err.println("Schema is invalid! Aborting...");
        return SCHEMA_SYNTAX_ERROR;
    }

    final JsonSchema schema = factory.getJsonSchema(uri);

    RetCode ret = ALL_OK, retcode;

    for (final File file : files) {
        node = MAPPER.readTree(file);
        retcode = reporter.validateInstance(schema, file.toString(), node);
        if (retcode != ALL_OK)
            ret = retcode;
    }

    return ret;
}

From source file:com.haulmont.yarg.formatters.impl.doc.connector.OfficeResourceProvider.java

protected String toURL(File file) {
    return "file://" + file.toURI().getRawPath();
}

From source file:com.hortonworks.registries.schemaregistry.client.ClassLoaderCache.java

public ClassLoaderCache(final SchemaRegistryClient schemaRegistryClient) {
    this.schemaRegistryClient = schemaRegistryClient;

    CacheLoader<String, ClassLoader> cacheLoader = new CacheLoader<String, ClassLoader>() {
        @Override//from  www  .  j  a v a 2  s  .  c  o m
        public ClassLoader load(String fileId) throws Exception {
            File file = getFile(fileId);
            return new URLClassLoader(new URL[] { file.toURI().toURL() });
        }
    };

    SchemaRegistryClient.Configuration configuration = schemaRegistryClient.getConfiguration();
    loadingCache = CacheBuilder.newBuilder()
            .maximumSize(
                    configuration.getValue(SchemaRegistryClient.Configuration.CLASSLOADER_CACHE_SIZE.name()))
            .expireAfterAccess(
                    configuration.getValue(
                            SchemaRegistryClient.Configuration.CLASSLOADER_CACHE_EXPIRY_INTERVAL_SECS.name()),
                    TimeUnit.SECONDS)
            .build(cacheLoader);

    localJarsDir = new File((String) schemaRegistryClient.getConfiguration()
            .getValue(SchemaRegistryClient.Configuration.LOCAL_JAR_PATH.name()));
    if (!localJarsDir.exists()) {
        if (!localJarsDir.mkdirs()) {
            throw new RuntimeException(
                    "Could not create given local jar storage dir: [" + localJarsDir.getAbsolutePath() + "]");
        }
    }
}

From source file:eu.europa.esig.dss.xades.signature.XAdESLevelBEnvelopedWithReferencesWithoutTransformationsTest.java

private DSSDocument createDocument(String filePath) throws IOException {
    File file = new File(filePath);
    byte[] content = IOUtils.toByteArray(file.toURI());
    return new InMemoryDocument(content, filePath);
}

From source file:com.splunk.shuttl.archiver.importexport.csv.CsvBucketCreator.java

private Bucket createBucketObject(File csvFile, Bucket bucket, File bucketDir) {
    try {//  ww  w .j av a2s . c  o  m
        String csvFileNameWithoutExtension = removeExtension(csvFile);
        return new Bucket(bucketDir.toURI(), bucket.getIndex(), csvFileNameWithoutExtension, BucketFormat.CSV,
                bucket.getSize());
    } catch (Exception e) {
        logBucketCreationException(bucket, bucketDir, e);
        throw new RuntimeException(e);
    }
}

From source file:com.splunk.shuttl.archiver.model.BucketTest.java

@Test(expectedExceptions = { FileNotDirectoryException.class })
public void uriConstructor_initWithFileUriToFileInsteadOfDirectory_throwsFileNotDirectoryException()
        throws IOException {
    File file = createFile();
    new Bucket(file.toURI(), null, null, null);
}

From source file:co.cask.tigon.sql.internal.StreamBinaryGenerator.java

private void unzipFile(File libZip) throws IOException, ArchiveException {
    String path = libZip.toURI().getPath();
    String outDir = libZip.getParentFile().getPath();
    TarArchiveInputStream archiveInputStream = new TarArchiveInputStream(
            new GZIPInputStream(new FileInputStream(path)));
    try {/*from  w ww  .  j  ava 2s . c om*/
        TarArchiveEntry entry = archiveInputStream.getNextTarEntry();
        while (entry != null) {
            File destFile = new File(outDir, entry.getName());
            destFile.getParentFile().mkdirs();
            if (!entry.isDirectory()) {
                ByteStreams.copy(archiveInputStream, Files.newOutputStreamSupplier(destFile));
                //TODO: Set executable permission based on entry.getMode()
                destFile.setExecutable(true, false);
            }
            entry = archiveInputStream.getNextTarEntry();
        }
    } finally {
        archiveInputStream.close();
    }
}