Example usage for java.io File getParent

List of usage examples for java.io File getParent

Introduction

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

Prototype

public String getParent() 

Source Link

Document

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

Usage

From source file:msearch.filmlisten.MSFilmlisteSchreiben.java

public void filmlisteSchreibenJson(String datei, ListeFilme listeFilme) {
    MSLog.systemMeldung("Filme schreiben (" + listeFilme.size() + " Filme) :");
    File file = new File(datei);
    File dir = new File(file.getParent());
    if (!dir.exists()) {
        if (!dir.mkdirs()) {
            MSLog.fehlerMeldung(915236478, MSLog.FEHLER_ART_PROG,
                    "MSearchIoXmlFilmlisteSchreiben.xmlSchreibenStart",
                    "Kann den Pfad nicht anlegen: " + dir.toString());
        }/*w  w w. j  ava2  s .co  m*/
    }
    MSLog.systemMeldung("   --> Start Schreiben nach: " + datei);
    try {
        String sender = "", thema = "";
        JsonFactory jsonF = new JsonFactory();
        JsonGenerator jg;
        if (datei.endsWith(MSConst.FORMAT_XZ)) {
            LZMA2Options options = new LZMA2Options();
            XZOutputStream out = new XZOutputStream(new FileOutputStream(file), options);
            jg = jsonF.createGenerator(out);
        } else if (datei.endsWith(MSConst.FORMAT_BZ2)) {
            bZip2CompressorOutputStream = new BZip2CompressorOutputStream(new FileOutputStream(file),
                    9 /*Blocksize: 1 - 9*/);
            jg = jsonF.createGenerator(bZip2CompressorOutputStream, JsonEncoding.UTF8);
        } else if (datei.endsWith(MSConst.FORMAT_ZIP)) {
            zipOutputStream = new ZipOutputStream(new FileOutputStream(file));
            ZipEntry entry = new ZipEntry(MSConst.XML_DATEI_FILME);
            zipOutputStream.putNextEntry(entry);
            jg = jsonF.createGenerator(zipOutputStream, JsonEncoding.UTF8);
        } else {
            jg = jsonF.createGenerator(new File(datei), JsonEncoding.UTF8);
        }
        jg.useDefaultPrettyPrinter(); // enable indentation just to make debug/testing easier
        jg.writeStartObject();
        // Infos zur Filmliste
        jg.writeArrayFieldStart(ListeFilme.FILMLISTE);
        for (int i = 0; i < ListeFilme.MAX_ELEM; ++i) {
            jg.writeString(listeFilme.metaDaten[i]);
        }
        jg.writeEndArray();
        // Infos der Felder in der Filmliste
        jg.writeArrayFieldStart(ListeFilme.FILMLISTE);
        for (int i = 0; i < DatenFilm.COLUMN_NAMES_JSON.length; ++i) {
            jg.writeString(DatenFilm.COLUMN_NAMES[DatenFilm.COLUMN_NAMES_JSON[i]]);
        }
        jg.writeEndArray();
        //Filme schreiben
        ListIterator<DatenFilm> iterator;
        DatenFilm datenFilm;
        iterator = listeFilme.listIterator();
        while (iterator.hasNext()) {
            datenFilm = iterator.next();
            jg.writeArrayFieldStart(DatenFilm.FILME_);
            for (int i = 0; i < DatenFilm.COLUMN_NAMES_JSON.length; ++i) {
                int m = DatenFilm.COLUMN_NAMES_JSON[i];
                if (m == DatenFilm.FILM_SENDER_NR) {
                    if (datenFilm.arr[m].equals(sender)) {
                        jg.writeString("");
                    } else {
                        sender = datenFilm.arr[m];
                        jg.writeString(datenFilm.arr[m]);
                    }
                } else if (m == DatenFilm.FILM_THEMA_NR) {
                    if (datenFilm.arr[m].equals(thema)) {
                        jg.writeString("");
                    } else {
                        thema = datenFilm.arr[m];
                        jg.writeString(datenFilm.arr[m]);
                    }
                } else {
                    jg.writeString(datenFilm.arr[m]);
                }
            }
            jg.writeEndArray();
        }
        jg.writeEndObject();
        jg.close();
        MSLog.systemMeldung("   --> geschrieben!");
    } catch (Exception ex) {
        MSLog.fehlerMeldung(846930145, MSLog.FEHLER_ART_PROG, "IoXmlSchreiben.FilmeSchreiben", ex,
                "nach: " + datei);
    }
}

From source file:msearch.io.MSFilmlisteSchreiben.java

public void filmlisteSchreibenJson(String datei, ListeFilme listeFilme) {
    MSLog.systemMeldung("Filme Schreiben (" + listeFilme.size() + " Filme) :");
    File file = new File(datei);
    File dir = new File(file.getParent());
    if (!dir.exists()) {
        if (!dir.mkdirs()) {
            MSLog.fehlerMeldung(915236478, MSLog.FEHLER_ART_PROG,
                    "MSearchIoXmlFilmlisteSchreiben.xmlSchreibenStart",
                    "Kann den Pfad nicht anlegen: " + dir.toString());
        }/*from ww  w  .j a v a 2  s  .c  om*/
    }
    MSLog.systemMeldung("   --> Start Schreiben nach: " + datei);
    try {
        String sender = "", thema = "";
        JsonFactory jsonF = new JsonFactory();
        JsonGenerator jg;
        if (datei.endsWith(MSConst.FORMAT_XZ)) {
            LZMA2Options options = new LZMA2Options();
            XZOutputStream out = new XZOutputStream(new FileOutputStream(file), options);
            jg = jsonF.createGenerator(out);
        } else if (datei.endsWith(MSConst.FORMAT_BZ2)) {
            bZip2CompressorOutputStream = new BZip2CompressorOutputStream(new FileOutputStream(file),
                    9 /*Blocksize: 1 - 9*/);
            jg = jsonF.createGenerator(bZip2CompressorOutputStream, JsonEncoding.UTF8);
        } else if (datei.endsWith(MSConst.FORMAT_ZIP)) {
            zipOutputStream = new ZipOutputStream(new FileOutputStream(file));
            ZipEntry entry = new ZipEntry(MSConst.XML_DATEI_FILME);
            zipOutputStream.putNextEntry(entry);
            jg = jsonF.createGenerator(zipOutputStream, JsonEncoding.UTF8);
        } else {
            jg = jsonF.createGenerator(new File(datei), JsonEncoding.UTF8);
        }
        jg.useDefaultPrettyPrinter(); // enable indentation just to make debug/testing easier
        jg.writeStartObject();
        // Infos zur Filmliste
        jg.writeArrayFieldStart(ListeFilme.FILMLISTE);
        for (int i = 0; i < ListeFilme.MAX_ELEM; ++i) {
            jg.writeString(listeFilme.metaDaten[i]);
        }
        jg.writeEndArray();
        // Infos der Felder in der Filmliste
        jg.writeArrayFieldStart(ListeFilme.FILMLISTE);
        for (int i = 0; i < DatenFilm.COLUMN_NAMES_JSON.length; ++i) {
            jg.writeString(DatenFilm.COLUMN_NAMES[DatenFilm.COLUMN_NAMES_JSON[i]]);
        }
        jg.writeEndArray();
        //Filme schreiben
        ListIterator<DatenFilm> iterator;
        DatenFilm datenFilm;
        iterator = listeFilme.listIterator();
        while (iterator.hasNext()) {
            datenFilm = iterator.next();
            jg.writeArrayFieldStart(DatenFilm.FILME_);
            for (int i = 0; i < DatenFilm.COLUMN_NAMES_JSON.length; ++i) {
                int m = DatenFilm.COLUMN_NAMES_JSON[i];
                if (m == DatenFilm.FILM_SENDER_NR) {
                    if (datenFilm.arr[m].equals(sender)) {
                        jg.writeString("");
                    } else {
                        sender = datenFilm.arr[m];
                        jg.writeString(datenFilm.arr[m]);
                    }
                } else if (m == DatenFilm.FILM_THEMA_NR) {
                    if (datenFilm.arr[m].equals(thema)) {
                        jg.writeString("");
                    } else {
                        thema = datenFilm.arr[m];
                        jg.writeString(datenFilm.arr[m]);
                    }
                } else {
                    jg.writeString(datenFilm.arr[m]);
                }
            }
            jg.writeEndArray();
        }
        jg.writeEndObject();
        jg.close();
        MSLog.systemMeldung("   --> geschrieben!");
    } catch (Exception ex) {
        MSLog.fehlerMeldung(846930145, MSLog.FEHLER_ART_PROG, "IoXmlSchreiben.FilmeSchreiben", ex,
                "nach: " + datei);
    }
}

From source file:ZipExploder.java

protected void copyFileEntry(String destDir, boolean destIsDir, String destFile, DataInputStream dis)
        throws IOException {
    byte[] bytes = readAllBytes(dis);
    File file = new File(destFile);
    String parent = file.getParent();
    if (parent != null && parent.length() > 0) {
        File dir = new File(destDir, parent);
        if (dir != null) {
            dir.mkdirs();/*from  www.jav a2s .  c  om*/
        }
    }
    File outFile = new File(destDir, destFile);
    if (destIsDir) {
        outFile.mkdir();
    } else {
        FileOutputStream fos = new FileOutputStream(outFile);
        try {
            fos.write(bytes, 0, bytes.length);
        } finally {
            try {
                fos.close();
            } catch (IOException ioe) {
            }
        }
    }
}

From source file:net.sourceforge.atunes.kernel.modules.plugins.PluginsHandler.java

/**
 * Removes a plugin from user plugins folder and updates plugins
 * //from   w w w. jav a 2 s .  c om
 * @param plugin
 * @throws IOException
 * @throws PluginSystemException
 */
public void uninstallPlugin(PluginInfo plugin) throws IOException, PluginSystemException {
    // Only remove plugins if are contained in a separate folder under user plugins folder
    File pluginLocation = new File(plugin.getPluginLocation());
    if (pluginLocation.getParent().equals(new File(getUserPluginsFolder()).getAbsolutePath())) {
        try {
            FileUtils.deleteDirectory(pluginLocation);
            factory.refresh();
        } catch (IOException e) {
            getLogger().error(LogCategories.PLUGINS, e);
            throw e;
        } catch (PluginSystemException e) {
            getLogger().error(LogCategories.PLUGINS, e);
            throw e;
        }
    }
}

From source file:com.cloudera.recordservice.tests.ClusterConfiguration.java

/**
 * This method unzips a conf dir return through the CM api and returns the
 * path of the unzipped directory as a string
 *//*  w w  w.j av a  2  s .co  m*/
private String unzipConf(String zipFileName) throws IOException {
    int num = rand_.nextInt(10000000);
    String outDir = "/tmp/" + "confDir" + "_" + num + "/";
    byte[] buffer = new byte[4096];
    FileInputStream fis;
    String filename = "";
    fis = new FileInputStream(zipFileName);
    ZipInputStream zis = new ZipInputStream(fis);
    ZipEntry ze = zis.getNextEntry();
    while (ze != null) {
        filename = ze.getName();
        File unzippedFile = new File(outDir + filename);
        // Ensure that parent directories exist
        new File(unzippedFile.getParent()).mkdirs();
        FileOutputStream fos = new FileOutputStream(unzippedFile);
        int len;
        while ((len = zis.read(buffer)) > 0) {
            fos.write(buffer, 0, len);
        }
        fos.close();
        zis.closeEntry();
        ze = zis.getNextEntry();
    }
    zis.closeEntry();
    zis.close();
    fis.close();
    return outDir + "recordservice-conf/";
}

From source file:cross.io.misc.DefaultConfigurableFileFilter.java

@Override
public boolean accept(final File f) {
    // First match path suffixes
    for (final String s : this.suffixesToMatch) {
        if (!s.isEmpty()) {
            log.debug("Checking {} against suffix {}", f.getParent(), s);
            if (f.getParent().endsWith(s)) {
                log.debug("FileFilter matched on suffix {}", s);
                return true;
            } else {
                this.log.debug("FileFilter did not match on suffix {} for string {}", s, f.getParent());
            }//from   w ww .  ja v  a 2 s .c  om
        }
    }
    // Second match filename prefixes
    for (final String s : this.prefixesToMatch) {
        if (!s.isEmpty()) {
            if (f.getName().startsWith(s)) {
                log.debug("FileFilter matched on prefix {}", s);
                return true;
            }
        }
    }
    // Third match filename extensions
    final String extension = StringTools.getFileExtension(f.getAbsolutePath());
    if (extension.equals(f.getName())) {
        log.warn("File has no proper file extension: {}", f);
        return false;
    } else {
        for (final String s : this.fileTypesToKeep) {
            if (extension.equalsIgnoreCase(s)) {
                log.debug("FileFilter matched on {}", extension);
                return true;
            }
        }
    }
    return false;
}

From source file:com.atlassian.clover.reporters.xml.XMLReporter.java

private XMLWriter initWriter() throws IOException {
    OutputStream os;//  w  w  w  .ja va 2  s. c  om

    final File outFile = reportConfig.getOutFile();
    if (outFile.getParent() != null && !outFile.getParentFile().exists()) {
        outFile.getParentFile().mkdirs();
    }
    if (reportConfig.isCompress()) {
        os = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(outFile)));
    } else {
        os = new BufferedOutputStream(new FileOutputStream(outFile));
    }
    return new XMLWriter(os, "UTF-8");
}

From source file:maltcms.ui.fileHandles.properties.tools.SceneExporter.java

/**
 * Layout: NAME/ NAME.properties NAME-general.properties (optional)
 * fragmentCommands/ 00_CLASSNAME/ CLASSNAME.properties 01_CLASSNAME/
 * CLASSNAME.properties/*from   w w  w .jav a2  s. c  o  m*/
 *
 * @param pipeline
 * @param general
 */
private void createConfigFiles(List<PipelineElementWidget> pipeline, PipelineGeneralConfigWidget general) {
    try {
        //create base config
        FileObject baseConfigFo = this.file.getFileObject(this.name + ".mpl");
        File f = FileUtil.toFile(baseConfigFo);
        PropertiesConfiguration baseConfig = new PropertiesConfiguration();
        File subDir = new File(f.getParent(), "xml");
        FileUtil.createFolder(subDir);
        //retrieve general configuration
        Configuration generalConfig = general.getProperties();
        //only create and link, if non-empty
        if (!generalConfig.isEmpty()) {
            ConfigurationUtils.copy(generalConfig, baseConfig);
        }
        //String list for pipeline elements
        List<String> pipelineElements = new LinkedList<>();
        File pipelineXml = new File(subDir, this.name + ".xml");
        for (PipelineElementWidget pw : pipeline) {
            //add full class name to pipeline elements
            pipelineElements.add(pw.getClassName());
            //write configuration to that file
            PropertiesConfiguration pc = new PropertiesConfiguration();
        }
        //set pipeline property
        baseConfig.setProperty("pipeline", pipelineElements);
        //set pipeline.properties property
        String pipelineXmlString = "file:${config.basedir}/xml/bipace.xml";
        baseConfig.setProperty("pipeline.xml", pipelineXmlString);
        FileObject fo = FileUtil.toFileObject(f);
        try {
            baseConfig.save(new PrintStream(fo.getOutputStream()));
        } catch (ConfigurationException ex) {
            Exceptions.printStackTrace(ex);
        }
    } catch (FileNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}

From source file:eu.planets_project.tb.gui.backing.admin.wsclient.faces.WSClientBean.java

/**
 * transforms a WS-I XML report to html using the corresponding stylesheet  
 * @param reportFile - the XML report file
 * @return the transformed HTML report file
 * @throws Exception//  w w  w . j a  v a 2s.  c o m
 */
private static File transformReport(File reportFile) throws Exception {

    String dir = System.getenv("WSI_HOME");
    File xsltFile = new File(dir + File.separatorChar + "common" + File.separatorChar + "xsl"
            + File.separatorChar + "report.xsl");

    Source xmlSource = new StreamSource(reportFile);
    Source xsltSource = new StreamSource(xsltFile);

    TransformerFactory transFact = TransformerFactory.newInstance();
    Transformer trans = transFact.newTransformer(xsltSource);

    String outputFolder = reportFile.getParent();
    File output = outputFolder == null || outputFolder.trim().length() == 0 ? null : new File(outputFolder);
    File tempFile = File.createTempFile("wsi-report", ".html", output);
    trans.transform(xmlSource, new StreamResult(tempFile));

    return tempFile;
}

From source file:com.pieframework.runtime.utils.ArtifactManager.java

private void copy(String download, String filter, String localPath, String virtualPath) {

    /*System.out.println("download:"+download+
             "\nfilter:"+filter+/*ww w  . j  ava 2  s.  c  om*/
             "\nlocalPath:"+localPath+
             "\nvirtualPath:"+virtualPath);
    */
    boolean match = true;
    if (!StringUtils.empty(filter)) {
        match = FilenameUtils.wildcardMatch(FilenameUtils.separatorsToSystem(download), filter);
    }

    if (match) {

        File destinationVirtualFile = new File(FilenameUtils.separatorsToSystem(virtualPath));
        File destination = new File(localPath + destinationVirtualFile.getParent());
        destination.mkdirs();

        if (destination.exists()) {
            File downloadFile = new File(download);
            try {
                FileUtils.copyFileToDirectory(downloadFile, destination);
                File copiedFile = new File(
                        destination.getPath() + File.separatorChar + destinationVirtualFile.getName());
                if (copiedFile.exists()) {
                    System.out.println(
                            "file copied:" + copiedFile + " crc:" + FileUtils.checksumCRC32(copiedFile));
                } else {
                    //TODO error
                }

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            //TODO error
        }

    }
}