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.athena.chameleon.engine.threadpool.task.FileEncodingConvertTaskTest.java

/**
 * <pre>//from   w ww .jav a 2s.co m
 *   ? ? ?  ??   ? ? ??  ?? .
 * </pre>
 * 
 * @throws java.lang.Exception
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
    File[] fileList = new File(FileEncodingConvertTaskTest.class.getResource("/converter/orig").getFile())
            .listFiles();

    for (File file : fileList) {
        copy(file, new File(file.getParentFile().getParent() + File.separator + file.getName()));
    }
}

From source file:com.ikon.module.db.stuff.FsDataStore.java

/**
 * Purge data store file/* w w  w  .  jav a  2 s  . co m*/
 */
public static void delete(String uuid) throws IOException {
    log.debug("delete({})", uuid);
    File fs = resolveFile(uuid);

    if (!fs.delete()) {
        throw new IOException("Could not delete file '" + fs.getParent() + "/" + uuid + "'");
    }
}

From source file:eu.eubrazilcc.lvl.oauth2.AllJUnitTests.java

@BeforeClass
public static void setup() {
    System.out.println("AllJUnitTests.setup()");
    final URL anchorURL = AllJUnitTests.class.getClassLoader().getResource(ANCHOR_FILENAME);
    File anchorFile = null;
    try {/*  w w w .  j  av a 2s .c o  m*/
        anchorFile = new File(anchorURL.toURI());
    } catch (Exception e) {
        anchorFile = new File(System.getProperty("user.dir"));
    }
    TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files");
    final File resDir = new File(TEST_RESOURCES_PATH);
    if (resDir != null && resDir.isDirectory() && resDir.canRead()) {
        try {
            TEST_RESOURCES_PATH = resDir.getCanonicalPath();
        } catch (IOException e) {
            // nothing to do
        }
    } else {
        throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH);
    }
    System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH);
    // load logging bridges
    LOG_MANAGER.preload();
    // system pre-loading
    LIGHT_CLOSER_SERVICE_MOCK.preload();
}

From source file:eu.eubrazilcc.lvl.storage.AllJUnitTests.java

@BeforeClass
public static void setup() {
    System.out.println("AllJUnitTests.setup()");
    final URL anchorURL = AllIntegrationTests.class.getClassLoader().getResource(ANCHOR_FILENAME);
    File anchorFile = null;
    try {//from  ww  w.  ja  v  a  2 s .  c o m
        anchorFile = new File(anchorURL.toURI());
    } catch (Exception e) {
        anchorFile = new File(System.getProperty("user.dir"));
    }
    TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files");
    final File resDir = new File(TEST_RESOURCES_PATH);
    if (resDir != null && resDir.isDirectory() && resDir.canRead()) {
        try {
            TEST_RESOURCES_PATH = resDir.getCanonicalPath();
        } catch (IOException e) {
            // nothing to do
        }
    } else {
        throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH);
    }
    System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH);
    // load logging bridges
    LOG_MANAGER.preload();
    // system pre-loading
    LIGHT_CLOSER_SERVICE_MOCK.preload();
}

From source file:com.adito.applications.server.FileReplacement.java

static File getTempFile(File near) throws IOException {
    String path = null;/*from   ww  w . jav a 2  s .  c o  m*/
    if (near != null)
        if (near.isFile())
            path = near.getParent();
        else if (near.isDirectory())
            path = near.getPath();

    Random wheel = new Random(); // seeded from the clock
    File tempFile = null;
    do {
        // generate random a number 10,000,000 .. 99,999,999
        int unique = (wheel.nextInt() & Integer.MAX_VALUE) % 90000000 + 10000000;
        tempFile = new File(path, Integer.toString(unique) + ".tmp");
    } while (tempFile.exists());
    // We "finally" found a name not already used. Nearly always the first
    // time.
    // Quickly stake our claim to it by opening/closing it to create it.
    // In theory somebody could have grabbed it in that tiny window since
    // we checked if it exists, but that is highly unlikely.
    new FileOutputStream(tempFile).close();

    // debugging peek at the name generated.
    if (false) {
        System.out.println(tempFile.getCanonicalPath());
    }
    return tempFile;
}

From source file:eu.eubrazilcc.lvl.storage.AllIntegrationTests.java

@BeforeClass
public static void setup() {
    System.out.println("AllIntegrationTests.setup()");
    final URL anchorURL = AllIntegrationTests.class.getClassLoader().getResource(ANCHOR_FILENAME);
    File anchorFile = null;
    try {//from   w  w w . j  a va  2s  .c  om
        anchorFile = new File(anchorURL.toURI());
    } catch (Exception e) {
        anchorFile = new File(System.getProperty("user.dir"));
    }
    TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files");
    final File resDir = new File(TEST_RESOURCES_PATH);
    if (resDir != null && resDir.isDirectory() && resDir.canRead()) {
        try {
            TEST_RESOURCES_PATH = resDir.getCanonicalPath();
        } catch (IOException e) {
            // nothing to do
        }
    } else {
        throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH);
    }
    System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH);
    // load logging bridges
    LOG_MANAGER.preload();
    // system pre-loading
    CLOSER_SERVICE_MOCK.preload();
}

From source file:eu.eubrazilcc.lvl.core.AllTests.java

@BeforeClass
public static void setup() {
    System.out.println("AllTests.setup()");
    final URL anchorURL = AllTests.class.getClassLoader().getResource(ANCHOR_FILENAME);
    File anchorFile = null;
    try {/* w  w w  . j  a va2s.  c o  m*/
        anchorFile = new File(anchorURL.toURI());
    } catch (Exception e) {
        anchorFile = new File(System.getProperty("user.dir"));
    }
    TEST_RESOURCES_PATH = concat(anchorFile.getParent(), "files");
    final File resDir = new File(TEST_RESOURCES_PATH);
    if (resDir != null && resDir.isDirectory() && resDir.canRead()) {
        try {
            TEST_RESOURCES_PATH = resDir.getCanonicalPath();
        } catch (IOException e) {
            // nothing to do
        }
    } else {
        throw new IllegalStateException("Invalid test resources pathname: " + TEST_RESOURCES_PATH);
    }
    System.out.println("Test resources pathname: " + TEST_RESOURCES_PATH);
    // load logging bridges
    LOG_MANAGER.preload();
    // system pre-loading
    CLOSER_SERVICE_MOCK.preload();
}

From source file:Main.java

public static String[] getMountedVolumes() {
    final String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // we can read the External Storage...           
        //Retrieve the primary External Storage:
        final File primaryExternalStorage = Environment.getExternalStorageDirectory();

        //Retrieve the External Storages root directory:
        String externalStorageRootDir = null;
        if ((externalStorageRootDir = primaryExternalStorage.getParent()) == null) { // no parent...
            return (new String[] { "ONLY A SINGLE VOLUME HAS BEEN DETECTED!",
                    (Environment.isExternalStorageRemovable() ? "(REMOVABLE SD-CARD)" : "(INTERNAL STORAGE)")
                            + " PRIMARY STORAGE: " + primaryExternalStorage });
        } else {/*from  w ww  . ja  v  a2  s .  c om*/
            final File externalStorageRoot = new File(externalStorageRootDir);
            final File[] files = externalStorageRoot.listFiles(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String filename) {
                    // TODO Auto-generated method stub

                    File file = new File(dir, filename);
                    if (file.isDirectory() && file.canRead() && file.canWrite() && !file.isHidden()) {
                        return true;
                    }
                    return false;
                }

            }); //.listFiles();
            List<String> data = new ArrayList<String>();
            if (files.length > 1) {
                data.add("MULTIPLE VOLUMES HAS BEEN DETECTED!");
                data.add("Enumerating detected volumes . . .");
            } else {
                data.add("ONLY A SINGLE VOLUME HAS BEEN DETECTED!");
            }

            for (final File file : files) {
                if (file.isDirectory() && file.canRead() && file.canWrite() && !file.isHidden()
                        && (files.length > 0)) { // it is a real directory (not a USB drive)...
                    if (file.toString().equals(primaryExternalStorage.toString()))
                        data.add((Environment.isExternalStorageRemovable() ? "(REMOVABLE SD-CARD)"
                                : "(INTERNAL Memory)") + " PRIMARY STORAGE: " + file.getAbsolutePath());
                    else {
                        data.add(((file.toString().contains("usb") || file.toString().contains("USB"))
                                ? "MOUNTED USB"
                                : "MOUNTED") + " STORAGE: " + file.getAbsolutePath());
                    }
                }
            }
            return data.toArray(new String[data.size()]);
        }
    } else {
        // we cannot read the External Storage..., return null
        return null;
    }

}

From source file:net.sf.jasperreports.samples.wizards.SampleNewWizard.java

public static void unpackArchive(File theFile, File targetDir, IProgressMonitor monitor, Set<String> cpaths,
        Set<String> lpaths) {
    byte[] buffer = new byte[1024];
    ZipInputStream zis = null;//from  ww  w . j  a  va 2  s  .c  o m
    try {
        zis = new ZipInputStream(new FileInputStream(theFile));

        ZipEntry ze = zis.getNextEntry();
        while (ze != null) {
            File file = new File(targetDir, File.separator + ze.getName());

            new File(file.getParent()).mkdirs();
            String fname = file.getName();
            if (ze.isDirectory()) {
                if (fname.equals("src"))
                    cpaths.add(ze.getName());
            } else {
                FileOutputStream fos = new FileOutputStream(file);
                int len;
                while ((len = zis.read(buffer)) > 0)
                    fos.write(buffer, 0, len);

                fos.close();
            }
            if (file.getParentFile().getName().equals("lib")
                    && (fname.endsWith(".jar") || fname.endsWith(".zip")))
                lpaths.add(ze.getName());
            if (monitor.isCanceled()) {
                zis.close();
                return;
            }
            ze = zis.getNextEntry();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            zis.closeEntry();
            zis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static void copyFile(File in, File out) throws IOException {
    FileInputStream fis = new FileInputStream(in);
    if (!out.exists()) {
        if (in.isDirectory()) {
            out.mkdirs();/*from   ww  w  .  jav a2  s .  c  o  m*/
        } else {
            File parentDir = new File(out.getParent());
            if (!parentDir.exists()) {
                parentDir.mkdirs();
            }
            out.createNewFile();
        }
    }
    FileOutputStream fos = new FileOutputStream(out);
    try {
        byte[] buf = new byte[8192];
        int i = 0;
        while ((i = fis.read(buf)) != -1)
            fos.write(buf, 0, i);
    } catch (IOException e) {
        throw e;
    } finally {
        fis.close();
        fos.close();
    }
}