Example usage for java.io File getCanonicalPath

List of usage examples for java.io File getCanonicalPath

Introduction

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

Prototype

public String getCanonicalPath() throws IOException 

Source Link

Document

Returns the canonical pathname string of this abstract pathname.

Usage

From source file:com.springsource.open.db.AtomikosApplication.java

@PostConstruct
public void init() throws Exception {
    File directory = new File("derby-home");
    System.setProperty("derby.system.home", directory.getCanonicalPath());
    System.setProperty("derby.storage.fileSyncTransactionLog", "true");
    System.setProperty("derby.storage.pageCacheSize", "100");
}

From source file:kieker.tools.bridge.cli.CLIServerMain.java

/**
 * Check for pid file./*from   w  w  w  .  j a va  2  s  .c o  m*/
 *
 * @return A pid file object
 * @throws IOException
 *             if file definition fails or the file already exists
 */
private static File getPidFile() throws IOException {
    File pidFile = null;
    if (System.getProperty(DAEMON_FILE) != null) {
        pidFile = new File(System.getProperty(DAEMON_FILE));
    } else {
        if (new File(System.getProperty(JAVA_TMP_DIR)).exists()) {
            pidFile = new File(System.getProperty(JAVA_TMP_DIR) + "/kdb.pid");
        } else {
            throw new IOException(
                    "Java temp directory " + System.getProperty(JAVA_TMP_DIR) + " does not exist.");
        }
    }
    if (pidFile.exists()) {
        throw new IOException("PID file " + pidFile.getCanonicalPath()
                + " already exists, indicating the service is already running.");
    }

    return pidFile;
}

From source file:com.twosigma.beakerx.kernel.PathToJar.java

public PathToJar(final String path) {
    checkNotNull(path);//from  w  w w. ja  va 2s  .c  o m
    File file = getFile(path);
    try {
        canonicalPath = file.getCanonicalPath();
        this.url = Paths.get(canonicalPath).toUri().toURL();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:ResettableFileInputStream.java

public ResettableFileInputStream(final File file) throws IOException {
    this(file.getCanonicalPath());
}

From source file:org.dbflute.utflute.spring.EmbeddedH2UrlFactoryBean.java

protected String getUrl() {
    try {/*w  w  w . j  av a2  s. co m*/
        final File buildDir = getBuildDir();
        final String canonicalPath = buildDir.getCanonicalPath();
        return "jdbc:h2:file:" + canonicalPath.replace('\\', '/') + _urlSuffix;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public boolean importData(JComponent comp, Transferable t) {
    DataFlavor[] flavors = t.getTransferDataFlavors();
    System.out.println("Trying to import:" + t);
    for (int i = 0; i < flavors.length; i++) {
        DataFlavor flavor = flavors[i];
        try {/*  w w  w  . j a v  a  2s.  c o m*/
            if (flavor.equals(DataFlavor.javaFileListFlavor)) {
                System.out.println("importData: FileListFlavor");
                List l = (List) t.getTransferData(DataFlavor.javaFileListFlavor);
                Iterator iter = l.iterator();
                while (iter.hasNext()) {
                    File file = (File) iter.next();
                    System.out.println("GOT FILE: " + file.getCanonicalPath());
                }
                return true;
            } else if (flavor.equals(DataFlavor.stringFlavor)) {
                System.out.println("importData: String Flavor");
                String fileOrURL = (String) t.getTransferData(flavor);
                System.out.println("GOT STRING: " + fileOrURL);
                try {
                    URL url = new URL(fileOrURL);
                    System.out.println("Valid URL: " + url.toString());
                    return true;
                } catch (MalformedURLException ex) {
                    System.err.println("Not a valid URL");
                    return false;
                }
            } else {
                System.out.println("importData rejected: " + flavor);
            }
        } catch (IOException ex) {
            System.err.println("IOError getting data: " + ex);
        } catch (UnsupportedFlavorException e) {
            System.err.println("Unsupported Flavor: " + e);
        }
    }
    return false;
}

From source file:com.blazemeter.bamboo.plugin.ServiceManager.java

public static File resolvePath(TaskContext context, String path, BuildLogger logger) throws Exception {
    File f = null;
    File root = new File("/");
    if (path.startsWith("/")) {
        f = new File(root, path);
    } else {/* w  ww.  j  a  v  a 2s . c  o m*/
        f = new File(context.getWorkingDirectory().getAbsolutePath() + "/build # "
                + context.getBuildContext().getBuildNumber(), path);
    }
    if (!f.exists()) {
        boolean mkDir = false;
        try {
            mkDir = f.mkdirs();
        } catch (Exception e) {
            throw new Exception("Failed to find filepath = " + f.getName());
        } finally {
            if (!mkDir) {
                logger.addBuildLogEntry(
                        "Failed to create " + f.getCanonicalPath() + " , workspace will be used.");
                f = new File(context.getWorkingDirectory(), path);
                f.mkdirs();
                logger.addBuildLogEntry("Resolving path into " + f.getCanonicalPath());
            }
        }
    }
    return f.getCanonicalFile();
}

From source file:it.cilea.osd.jdyna.web.controller.FileServiceController.java

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String idString = request.getPathInfo();
    String[] pathInfo = idString.split("/", 4);

    String folder = pathInfo[3];//w  w  w .  j av a  2s . c o m
    String fileName = request.getParameter("filename");

    File dir = new File(getPath() + File.separatorChar + folder);
    File file = new File(dir, fileName);

    if (file.getCanonicalPath().replace("\\", "/").startsWith(dir.getCanonicalPath().replace("\\", "/"))) {
        if (file.exists()) {
            InputStream is = null;
            try {
                is = new FileInputStream(file);

                response.setContentType(request.getSession().getServletContext().getMimeType(file.getName()));
                Long len = file.length();
                response.setContentLength(len.intValue());
                response.setHeader("Content-Disposition", "attachment; filename=" + file.getName());
                FileCopyUtils.copy(is, response.getOutputStream());
                response.getOutputStream().flush();
            } finally {
                if (is != null) {
                    is.close();
                }

            }
        } else {
            throw new RuntimeException("File doesn't exists!");
        }
    } else {
        throw new RuntimeException("No permission to download this file");
    }
    return null;
}

From source file:org.nekorp.workflow.desktop.servicio.reporte.orden.servicio.GeneradorOrdenServicio.java

@Override
public void generaReporte(ParametrosReporteOS param) {
    try {//from www .j  av  a  2s . co m
        File jasperFile = new File("OrdenServicio.jasper");
        String fileName = jasperFile.getCanonicalPath();
        String outFileName = param.getDestination().getCanonicalPath();
        HashMap hm = new HashMap();
        JasperPrint print = JasperFillManager.fillReport(fileName, hm,
                new JRBeanCollectionDataSource(ordenServicioDataFactory.getDatosOS(param)));
        JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
        exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outFileName);
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
        exporter.exportReport();
    } catch (JRException e) {
        GeneradorOrdenServicio.LOGGER.error("error al generar pdf", e);
        mensajesControl.reportaError("Error al generar PDF/n" + e.getMessage());
    } catch (Exception e) {
        GeneradorOrdenServicio.LOGGER.error("error al generar pdf", e);
        mensajesControl.reportaError("Error al generar PDF/n" + e.getMessage());
    }
}

From source file:com.ariht.maven.plugins.config.io.FileInfo.java

private String getRelativeSubDirectoryAndFilename(final File file) throws IOException {
    return file.getCanonicalPath() + "/" + getName();
}