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:com.aurel.track.lucene.util.FileUtil.java

public static void write(File file, String s, boolean lazy) throws IOException {

    if (file.getParent() != null) {
        mkdirs(file.getParent());// w ww. ja  v a 2s .c o m
    }

    if (file.exists()) {
        String content = FileUtil.read(file);

        if (content.equals(s)) {
            return;
        }
    }

    BufferedWriter bw = new BufferedWriter(new FileWriter(file));

    bw.flush();
    bw.write(s);

    bw.close();
}

From source file:org.jamwiki.utils.ImageUtil.java

/**
 * Save an image to a specified file.//from   w w w .  ja v  a2 s . co  m
 */
private static void saveImage(BufferedImage image, File file) throws Exception {
    String filename = file.getName();
    int pos = filename.lastIndexOf('.');
    if (pos == -1 || (pos + 1) >= filename.length()) {
        throw new Exception("Unknown image type " + filename);
    }
    String imageType = filename.substring(pos + 1);
    File imageFile = new File(file.getParent(), filename);
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(imageFile);
        ImageIO.write(image, imageType, fos);
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (Exception e) {
            }
        }
    }
}

From source file:dynamicrefactoring.domain.xml.ExportImportUtilities.java

/**
 * Modifica la refactorizacion para poder importarla.
 * // w  w w.  ja  v a2  s  .  com
 * @param definitionFile
 *            fichero de definicion de la refactorizacion
 * @param refact
 *            refactorizacion a modificar
 * @return refactorizacion modificada
 */
private static DynamicRefactoringDefinition modifyRefactToImportIt(File definitionFile,
        DynamicRefactoringDefinition refact) {
    Builder builder = refact.getBuilder();
    if (!refact.getImage().isEmpty() && !new File(refact.getImage()).isAbsolute()) {
        builder = builder.image(definitionFile.getParent() + "/" + refact.getImage());
    }

    return builder.examples(getExamplesWithOtherRootFolder(definitionFile.getParent(), refact)).build();
}

From source file:com.cloud.utils.SwiftUtil.java

public static String putObject(SwiftClientCfg cfg, File srcFile, String container, String fileName) {
    if (fileName == null) {
        fileName = srcFile.getName();/*  w ww .j  a  va  2 s  .  com*/
    }

    Script command = new Script("/bin/bash", logger);
    command.add("-c");
    command.add(String.format(CD_SRC, srcFile.getParent())
            + getUploadObjectCommand(cfg, getSwiftCLIPath(), container, fileName, srcFile.length()));

    OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
    String result = command.execute(parser);
    if (result != null) {
        throw new CloudRuntimeException("Failed to upload file: " + result);
    }

    if (parser.getLines() != null) {
        String[] lines = parser.getLines().split("\\n");
        for (String line : lines) {
            if (line.contains("Errno") || line.contains("failed") || line.contains("not found")) {
                throw new CloudRuntimeException("Failed to upload file: " + Arrays.toString(lines));
            }
        }
    }

    return container + File.separator + srcFile.getName();
}

From source file:com.tascape.qa.th.Utils.java

public static File getKeepAliveFile(File file) {
    String name = Utils.getKeepAliveFileName(file.getName());
    return Paths.get(file.getParent(), name).toFile();
}

From source file:net.sf.jvifm.util.AutoCompleteUtil.java

public static List<File> getFileCompleteList(String pwd, String path, boolean onlyDir) {
    List<File> list = new ArrayList<File>();
    String fileName = new File(path).getName();

    if (path.endsWith(":"))
        return null;

    File file = new File(FilenameUtils.concat(pwd, path));

    File pwdFile = null;//from  w  w  w.j  a  v  a 2s. c om
    pwdFile = file;
    if (path.endsWith(File.separator) || path.trim().equals("")) {
        pwdFile = file;
    } else {
        if (file.getParent() == null)
            return null;
        pwdFile = new File(file.getParent());
    }
    if (!pwdFile.exists())
        return null;
    File[] files = pwdFile.listFiles((FileFilter) Util.getDefaultFileFilter());

    if (files == null || files.length <= 0)
        return null;
    boolean lowerCase = false;
    if (fileName.toLowerCase().equals(fileName)) {
        lowerCase = true;
    }
    for (int i = 0; i < files.length; i++) {
        String tmpFileName = files[i].getName();
        if (lowerCase)
            tmpFileName = tmpFileName.toLowerCase();
        if (tmpFileName.startsWith(fileName) || path.endsWith(File.separator)
                || FilenameUtils.wildcardMatch(tmpFileName, fileName, IOCase.INSENSITIVE))
            if (onlyDir) {
                if (files[i].isDirectory())
                    list.add(files[i]);
            } else {
                list.add(files[i]);
            }
    }
    if (list.size() <= 0)
        return null;
    return list;
}

From source file:com.wipro.ats.bdre.filemon.FileScan.java

public static void scanAndAddToQueue() {
    try {//  w  w w .java 2s. c om
        String scanDir = FileMonRunnableMain.getMonitoredDirName();
        LOGGER.debug("Scanning directory: " + scanDir);
        File dir = new File(scanDir);
        if (!dir.exists()) {
            LOGGER.info("Created monitoring dir " + dir + " success=" + dir.mkdirs());
        }
        File arcDir = new File(scanDir + "/" + FileMonRunnableMain.ARCHIVE);
        if (!arcDir.exists()) {
            LOGGER.info("Created monitoring dir " + arcDir + " success=" + arcDir.mkdirs());
        }
        // Getting list of files recursively from directory except '_archive' directory
        Collection<File> listOfFiles = FileUtils.listFiles(dir,
                new RegexFileFilter(FileMonRunnableMain.getFilePattern()),
                new RegexFileFilter("^(?:(?!" + FileMonRunnableMain.ARCHIVE + ").)*$"));
        String fileName = "";
        FileCopyInfo fileCopyInfo = null;
        for (File file : listOfFiles) {
            fileName = file.getName();
            LOGGER.debug("Matched File Pattern by " + fileName);
            fileCopyInfo = new FileCopyInfo();
            fileCopyInfo.setFileName(fileName);
            fileCopyInfo.setSubProcessId(FileMonRunnableMain.getSubProcessId());
            fileCopyInfo.setServerId(Integer.toString(123461));
            fileCopyInfo.setSrcLocation(file.getAbsolutePath());
            fileCopyInfo.setDstLocation(file.getParent().replace(FileMonRunnableMain.getMonitoredDirName(),
                    FileMonRunnableMain.getHdfsUploadDir()));
            fileCopyInfo.setFileHash(DigestUtils.md5Hex(FileUtils.readFileToByteArray(file)));
            fileCopyInfo.setFileSize(file.length());
            fileCopyInfo.setTimeStamp(file.lastModified());
            FileMonitor.addToQueue(fileName, fileCopyInfo);
        }
    } catch (Exception err) {
        LOGGER.error("Error in scan directory ", err);
        throw new BDREException(err);
    }
}

From source file:at.medevit.elexis.gdt.handler.GDTFileInputHandler.java

public static void handle(File file) {
    String[] lines = readFileGetUTF8(file);
    int satzkennung = 0;

    if (lines != null) {
        String satzkennungString = GDTSatzNachrichtHelper
                .getValueIfExists(GDTConstants.FELDKENNUNG_SATZIDENTIFIKATION, lines);
        satzkennung = Integer.parseInt(satzkennungString);
    }/*www .ja v  a 2  s.  c  om*/

    IGDTCommunicationPartner cp = GDTCommPartnerCollector
            .identifyCommunicationPartnerByIncomingDirectory(file.getParent());

    boolean delivered = false;

    switch (satzkennung) {
    case GDTConstants.SATZART_STAMMDATEN_ANFORDERN:
        delivered = GDTInputHandler.handleSatznachricht6300(lines, file.getName(), cp);
        if (delivered)
            delete(file);
        break;
    case GDTConstants.SATZART_DATEN_EINER_UNTERSUCHUNG_UEBERMITTELN:
        delivered = GDTInputHandler.handleSatznachricht6310(lines, file.getName(), cp);
        if (delivered)
            delete(file);
        break;
    case GDTConstants.SATZART_DATEN_EINER_UNTERSUCHUNG_ZEIGEN:
        GDTInputHandler.handleSatznachricht6311(lines, file.getName(), cp);
        break;
    case GDTConstants.SATZART_STAMMDATEN_UEBERMITTELN:
        GDTInputHandler.handleSatznachricht6301(lines, file.getName(), cp);
        break;
    case GDTConstants.SATZART_UNTERSUCHUNG_ANFORDERN:
        GDTInputHandler.handleSatznachricht6302(lines, file.getName(), cp);
    default:
        break;
    }
}

From source file:com.zimbra.cs.service.util.ItemDataFile.java

public static void create(String path, Set<MailItem.Type> types, String cset, OutputStream os)
        throws IOException {
    File f = new File(path);
    TarOutputStream tos = new TarOutputStream(new GZIPOutputStream(os), cset == null ? "UTF-8" : cset);

    tos.setLongFileMode(TarOutputStream.LONGFILE_GNU);
    try {//from  ww w. j av  a2s  .  c o m
        if (f.isDirectory())
            addDir(f, f.getPath(), types, tos);
        else
            addFile(f, f.getParent(), types, tos);
    } finally {
        tos.close();
    }
}

From source file:net.pms.newgui.StatusTab.java

public static BufferedImage getRendererIcon(String icon) {
    BufferedImage bi = null;/*from  w w w .java 2  s  . c om*/

    if (icon != null) {

        if (icon.matches(".*\\S+://.*")) {
            try {
                bi = ImageIO.read(new URL(icon));
            } catch (Exception e) {
                LOGGER.debug("Error reading icon url: " + e);
            }
            if (bi != null) {
                return bi;
            } else {
                LOGGER.debug("Unable to read icon url \"{}\", using '{}' instead.",
                        RendererConfiguration.UNKNOWN_ICON);
                icon = RendererConfiguration.UNKNOWN_ICON;
            }
        }

        try {
            InputStream is = null;

            /**
             * Check for a custom icon file first
             *
             * The file can be a) the name of a file in the renderers directory b) a path relative
             * to the PMS working directory or c) an absolute path. If no file is found,
             * the built-in resource (if any) is used instead.
             *
             * The File constructor does the right thing for the relative and absolute path cases,
             * so we only need to detect the bare filename case.
             *
             * RendererIcon = foo.png // e.g. $PMS/renderers/foo.png
             * RendererIcon = images/foo.png // e.g. $PMS/images/foo.png
             * RendererIcon = /path/to/foo.png
             */

            File f = new File(icon);

            if (!f.isAbsolute() && f.getParent() == null) { // filename
                f = new File("renderers", icon);
            }

            if (f.isFile()) {
                is = new FileInputStream(f);
            }

            if (is == null) {
                is = LooksFrame.class.getResourceAsStream("/resources/images/clients/" + icon);
            }

            if (is == null) {
                is = LooksFrame.class.getResourceAsStream("/renderers/" + icon);
            }

            if (is != null) {
                bi = ImageIO.read(is);
            }
        } catch (IOException e) {
            LOGGER.debug("Caught exception", e);
        }
    }
    if (bi == null) {
        LOGGER.debug("Failed to load icon: " + icon);
    }
    return bi;
}