Example usage for java.io File getParentFile

List of usage examples for java.io File getParentFile

Introduction

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

Prototype

public File getParentFile() 

Source Link

Document

Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.

Usage

From source file:ar.com.fdvs.dj.test.ReportExporter.java

public static void exportReportHtml(JasperPrint jp, String path) throws JRException, FileNotFoundException {
    JRHtmlExporter exporter = new JRHtmlExporter();

    File outputFile = new File(path);
    File parentFile = outputFile.getParentFile();
    if (parentFile != null)
        parentFile.mkdirs();/*from  w  w  w  .ja  va2  s. c  o m*/
    FileOutputStream fos = new FileOutputStream(outputFile);

    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fos);
    exporter.exportReport();

    logger.debug("HTML Report exported: " + path);
}

From source file:Main.java

public static void upZipFile(File zipFile, String folderPath) {
    ZipFile zf;/*from w  w w .  ja  va2  s.  c  o  m*/
    try {
        zf = new ZipFile(zipFile);
        for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements();) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            if (entry.isDirectory()) {
                String dirstr = entry.getName();
                dirstr = new String(dirstr.getBytes("8859_1"), "GB2312");
                File f = new File(dirstr);
                f.mkdir();
                continue;
            }

            InputStream in = zf.getInputStream(entry);
            String str = folderPath + File.separator + entry.getName();
            str = new String(str.getBytes("8859_1"), "GB2312");
            File desFile = new File(str);
            if (!desFile.exists()) {
                File fileParentDir = desFile.getParentFile();
                if (!fileParentDir.exists()) {
                    fileParentDir.mkdirs();
                }
                desFile.createNewFile();
            }

            OutputStream out = new FileOutputStream(desFile);
            byte buffer[] = new byte[BUFF_SIZE];
            int realLength;
            while ((realLength = in.read(buffer)) > 0) {
                out.write(buffer, 0, realLength);
            }
            in.close();
            out.close();
        }
    } catch (ZipException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:ar.com.init.agros.reporting.dj.ReportExporter.java

public static void exportReportXLS(JasperPrint jp, String path) throws JRException, FileNotFoundException {
    JRXlsExporter exporter = new JRXlsExporter();

    File outputFile = new File(path);
    File parentFile = outputFile.getParentFile();
    if (parentFile != null) {
        parentFile.mkdirs();/*from  w w w .java2 s.c  om*/
    }
    FileOutputStream fos = new FileOutputStream(outputFile);

    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fos);
    exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
    exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
    exporter.setParameter(JRXlsExporterParameter.IS_IGNORE_GRAPHICS, Boolean.FALSE);

    exporter.setParameter(JRXlsExporterParameter.IS_IGNORE_GRAPHICS, Boolean.FALSE);
    exporter.setParameter(JRXlsExporterParameter.IGNORE_PAGE_MARGINS, Boolean.TRUE);
    exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
    exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
    exporter.setParameter(JRXlsExporterParameter.IS_IGNORE_CELL_BORDER, Boolean.TRUE);

    exporter.exportReport();

    logger.info("XLS Report exported: " + path);
}

From source file:com.canoo.webtest.util.WebtestEmbeddingUtil.java

/**
 * Copies WebTest resources (ie webtest.xml, tools/*, the XSLs, CSSs and pictures, ...) package in WebTest jar file
 * into the provide folder. Indeed different Ant tasks can't work with resources in a jar file.
 * @param targetFolder the folder in which resources should be copied to
 * @throws java.io.IOException if the resources can be accessed or copied
 *//*from   w w w  . j  a v  a  2s .c om*/
static void copyWebTestResources(final File targetFolder) throws IOException {
    final String resourcesPrefix = "com/canoo/webtest/resources/";
    final URL webtestXmlUrl = WebtestEmbeddingUtil.class.getClassLoader()
            .getResource(resourcesPrefix + "webtest.xml");

    if (webtestXmlUrl == null) {
        throw new IllegalStateException("Can't find resource " + resourcesPrefix + "webtest.xml");
    } else if (webtestXmlUrl.toString().startsWith("jar:file")) {
        final String urlJarFileName = webtestXmlUrl.toString().replaceFirst("^jar:file:([^\\!]*).*$", "$1");
        final String jarFileName = URLDecoder.decode(urlJarFileName, Charset.defaultCharset().name());
        final JarFile jarFile = new JarFile(jarFileName);
        final String urlPrefix = StringUtils.removeEnd(webtestXmlUrl.toString(), "webtest.xml");

        for (final Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
            final JarEntry jarEntry = entries.nextElement();
            if (jarEntry.getName().startsWith(resourcesPrefix)) {
                final String relativeName = StringUtils.removeStart(jarEntry.getName(), resourcesPrefix);
                final URL url = new URL(urlPrefix + relativeName);
                final File targetFile = new File(targetFolder, relativeName);
                FileUtils.forceMkdir(targetFile.getParentFile());
                FileUtils.copyURLToFile(url, targetFile);
            }
        }
    } else if (webtestXmlUrl.toString().startsWith("file:")) {
        // we're probably developing and/or have a custom version of the resources in classpath
        final File webtestXmlFile = FileUtils.toFile(webtestXmlUrl);
        final File resourceFolder = webtestXmlFile.getParentFile();

        FileUtils.copyDirectory(resourceFolder, targetFolder);
    } else {
        throw new IllegalStateException(
                "Resource " + resourcesPrefix + "webtest.xml is not in a jar file: " + webtestXmlUrl);
    }
}

From source file:com.googlecode.t7mp.util.ZipUtil.java

public static void unzip(InputStream warInputStream, File destination) {
    try {//  w ww  .jav a2s . c  o  m
        ZipArchiveInputStream in = null;
        try {
            in = new ZipArchiveInputStream(warInputStream);

            ZipArchiveEntry entry = null;
            while ((entry = in.getNextZipEntry()) != null) {
                File outfile = new File(destination.getCanonicalPath() + "/" + entry.getName());
                outfile.getParentFile().mkdirs();
                if (entry.isDirectory()) {
                    outfile.mkdir();
                    continue;
                }
                OutputStream o = new FileOutputStream(outfile);
                try {
                    IOUtils.copy(in, o);
                } finally {
                    o.close();
                }
            }
        } finally {
            if (in != null) {
                in.close();
            }
        }
        warInputStream.close();
    } catch (FileNotFoundException e) {
        throw new TomcatSetupException(e.getMessage(), e);
    } catch (IOException e) {
        throw new TomcatSetupException(e.getMessage(), e);
    }
}

From source file:com.junoyoon.BullsUtil.java

public static void copyResource(String toDir, String fileName) throws IOException {
    File file = new File(toDir);
    if (!file.getParentFile().exists()) {
        file.getParentFile().mkdirs();//from   w w  w.ja v a  2 s.c  o m
    }
    try {
        InputStream is = BullsUtil.class.getClassLoader().getResourceAsStream(fileName);
        FileOutputStream fs = new FileOutputStream(toDir);
        IOUtils.copy(is, fs);
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(fs);
    } catch (Exception e) {
        BullsHtml.printErrorAndExit(e);
    }
}

From source file:ar.com.fdvs.dj.test.ReportExporter.java

/**
 * The path to the file must exist.//from  ww w .  j a v  a  2 s.c  om
 * @param jp
 * @param path
 * @throws JRException
 * @throws FileNotFoundException
 */
public static void exportReport(JasperPrint jp, String path) throws JRException, FileNotFoundException {
    JRPdfExporter exporter = new JRPdfExporter();

    File outputFile = new File(path);
    File parentFile = outputFile.getParentFile();
    if (parentFile != null)
        parentFile.mkdirs();
    FileOutputStream fos = new FileOutputStream(outputFile);

    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fos);

    exporter.exportReport();

    logger.debug("Report exported: " + path);
}

From source file:daily.test.ReportExporter.java

public static void exportReportHtml(JasperPrint jp, String path) throws JRException, FileNotFoundException {
    JRHtmlExporter exporter = new JRHtmlExporter();

    File outputFile = new File(path);
    File parentFile = outputFile.getParentFile();
    if (parentFile != null)
        parentFile.mkdirs();//www  . ja  v a 2  s.c om
    FileOutputStream fos = new FileOutputStream(outputFile);

    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fos);
    //exporter.setParameter(JRExporterParameter.PAGE_INDEX,1);
    exporter.exportReport();

    logger.debug("HTML Report exported: " + path);
}

From source file:com.nas.recovery.web.action.incidents.ReportExporter.java

/**
 * The path to the file must exist./*w w w  .  j  av a 2 s  .  c o  m*/
 * @param jp
 * @param path
 * @throws JRException
 * @throws FileNotFoundException
 */
public static void exportReport(JasperPrint jp, String path) throws JRException, FileNotFoundException {
    logger.debug("Exporing report to: " + path);
    JRPdfExporter exporter = new JRPdfExporter();

    File outputFile = new File(path);
    File parentFile = outputFile.getParentFile();
    if (parentFile != null)
        parentFile.mkdirs();
    FileOutputStream fos = new FileOutputStream(outputFile);

    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fos);

    exporter.exportReport();

    logger.debug("Report exported: " + path);
}

From source file:de.ingrid.iplug.csw.dsc.TestUtil.java

public static void copy(File sourceFile, File targetFile) {
    targetFile.getParentFile().mkdirs();
    try {/*from   w  w w.j a  v a 2  s  .c o m*/
        InputStream in = new FileInputStream(sourceFile);
        OutputStream out = new FileOutputStream(targetFile);
        copy(in, out, true);
    } catch (IOException e) {
        throw new RuntimeException("could not copy " + sourceFile + " to " + targetFile, e);
    }
}