Example usage for java.io File getAbsoluteFile

List of usage examples for java.io File getAbsoluteFile

Introduction

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

Prototype

public File getAbsoluteFile() 

Source Link

Document

Returns the absolute form of this abstract pathname.

Usage

From source file:hu.sztaki.lpds.pgportal.services.dspace.DSpaceUtil.java

/**
 * Extracts any file from <code>inputFile</code> that begins with
 * 'bitstream' to <code>outputFile</code>.
 * Adapted from examples on//from   w  w w.  j a v  a2s .co m
 * http://java.sun.com/developer/technicalArticles/Programming/compression/
 *
 * @param inputFile  File to extract 'bitstream...' from
 * @param outputFile  File to extract 'bitstream...' to
 */
private static void unzipBitstream(InputStream is, File outputFile) throws IOException {
    final int BUFFER = 2048;
    BufferedOutputStream dest = null;
    ZipInputStream zis = new ZipInputStream(is);
    ZipEntry entry;
    try {

        while ((entry = zis.getNextEntry()) != null) {
            if (entry.getName().matches("bitstream.*")) {
                int count;
                byte data[] = new byte[BUFFER];

                // write the files to the disk
                FileOutputStream fos = new FileOutputStream(outputFile.getAbsoluteFile());
                dest = new BufferedOutputStream(fos, BUFFER);
                while ((count = zis.read(data, 0, BUFFER)) != -1) {
                    dest.write(data, 0, count);
                    //System.out.println("Writing: " + outputFile.getAbsoluteFile());
                }
                dest.flush();
                dest.close();
            }
        }
    } finally {
        zis.close();
        try {
            dest.close();
        } catch (Exception e) {
        }
    }
}

From source file:com.plusub.lib.util.CacheUtils.java

public static CacheUtils get(File cacheDir, long max_zise, int max_count) {
    CacheUtils manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
    if (manager == null) {
        manager = new CacheUtils(cacheDir, max_zise, max_count);
        mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
    }/*from ww  w .j a  v  a 2 s  . c  o m*/
    return manager;
}

From source file:cn.edu.sdust.silence.itransfer.filemanage.FileManager.java

private static boolean isSymlink(File file) throws IOException {
    File fileInCanonicalDir = null;
    if (file.getParent() == null) {
        fileInCanonicalDir = file;//from www .  ja  v a2  s  . c  o m
    } else {
        File canonicalDir = file.getParentFile().getCanonicalFile();
        fileInCanonicalDir = new File(canonicalDir, file.getName());
    }
    return !fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile());
}

From source file:com.guodong.sun.guodong.uitls.CacheUtil.java

public static CacheUtil get(File cacheDir, long maxZise, int maxCount) {
    CacheUtil manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
    if (manager == null) {
        manager = new CacheUtil(cacheDir, maxZise, maxCount);
        mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
    }/* w  w w . j av a 2 s  . c om*/
    return manager;
}

From source file:com.freedomotic.environment.impl.EnvironmentRepositoryImpl.java

/**
 *
 *
 * @param folder//from   www.  j  a  va 2s.co m
 * @throws RepositoryException
 */
private static void deleteEnvFiles(File folder) throws RepositoryException {
    if ((folder == null) || !folder.isDirectory()) {
        throw new IllegalArgumentException("Unable to delete environment files in a null or not valid folder");
    }

    // this filter only returns thing files
    FileFilter objectFileFileter = new FileFilter() {
        @Override
        public boolean accept(File file) {
            if (file.isFile() && file.getName().endsWith(ENVIRONMENT_FILE_EXTENSION)) {
                return true;
            } else {
                return false;
            }
        }
    };

    File[] files = folder.listFiles(objectFileFileter);

    for (File file : files) {
        boolean deleted = file.delete();

        if (!deleted) {
            throw new RepositoryException("Unable to delete file " + file.getAbsoluteFile());
        }
    }
}

From source file:dbconverter.dao.util.ToolKit.java

/**
 * Method will provide a .json file for a specific Elasticsearch index and type so that it can be loaded
 *  via Elasticsearch Bulkload/*from   www . j  a  va2 s  . c o  m*/
 * If there already exists a file with name = jsonFileName, this will append to that file
 * @param indexName - name of the Elasticsearch index this .json bulk load is being built for
 * @param typeName - name of the Elasticsearch type this .json bulk load is being built for
 * @param jsonFileName - name of the .json file that will be created
 * @param jsonObjectData - The JSON object data that will be written to .json file.
 */
public static void writeToElasticsearchBulkLoadJsonFile(String indexName, String typeName, String jsonFileName,
        List<String> jsonObjectData) {

    int numberOfJsonObjects = jsonObjectData.size();
    List<String> jsonBulkLoadList = new ArrayList<>();

    for (int i = 0; i < numberOfJsonObjects; i++) {
        // This map will build the index map portion for the bulk load
        Map<String, Object> indexMap = new HashMap<>();
        indexMap.put("_index", indexName);
        indexMap.put("_type", typeName);
        indexMap.put("_id", i);

        String mapData = ToolKit.convertMapToJson(indexMap);

        // wrap the document in an index command
        indexMap = new HashMap<>();
        indexMap.put("index", mapData);

        String esIndex = ToolKit.convertMapToJson(indexMap);

        jsonBulkLoadList.add(esIndex + "\n");
        jsonBulkLoadList.add(jsonObjectData.get(i) + "\n");
    }

    File file = new File(jsonFileName);

    for (String bulkLoadData : jsonBulkLoadList) {
        try {
            FileUtils.writeStringToFile(file, bulkLoadData, true);
        } catch (IOException ex) {
            logger.error("Could not write " + bulkLoadData + " to file " + file.getAbsoluteFile(), ex);
        }
    }

}

From source file:com.neosdong.dimensionnews.Utils.ACache.java

public static ACache get(File cacheDir, long max_zise, int max_count) {

    if (C.APP_DEBUG) {
        Log.d(TAG, "ACache.get - cacheDir:" + cacheDir);
    }/*from   ww  w  .  ja va  2 s .c  o  m*/

    ACache manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
    if (manager == null) {
        manager = new ACache(cacheDir, max_zise, max_count);
        mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
    }
    return manager;
}

From source file:com.linked.erfli.library.utils.ACache.java

public static ACache get(File cacheDir, long max_zise, int max_count) {
    //key+??idmapvaluemanager
    ACache manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
    if (manager == null) {
        manager = new ACache(cacheDir, max_zise, max_count);
        mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
    }//from w w  w.ja  v a 2  s  .  c o  m
    return manager;
}

From source file:com.blackbird.utils.ACache.java

public static ACache get(File cacheDir, long max_zise, int max_count) {
    ///data/data/com.yangfuhai.asimplecachedemo/cache/ACache
    ACache manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
    if (manager == null) {
        manager = new ACache(cacheDir, max_zise, max_count);
        //{/data/data/com.yangfuhai.asimplecachedemo/cache/ACache_4137=org.afinal.simplecache.ACache@2bc38270}
        //{/data/data/com.yangfuhai.asimplecachedemo/cache/ACache_12189=org.afinal.simplecache.ACache@2bc3d890}
        mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
    }//w w w.  jav  a 2  s  .  co m
    return manager;
}

From source file:com.emin.digit.mobile.android.storage.cache.FileCache.java

public static FileCache get(File cacheDir, long max_zise, int max_count) {
    debug("2 ---- cacheDir.getAbsolutePath():" + cacheDir.getAbsolutePath());
    debug("2.1 myPid()" + myPid());

    FileCache cache = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());

    debug("3 ---- Key:cacheDir.getAbsoluteFile() + myPid():" + cacheDir.getAbsoluteFile() + myPid()); // ACache_15086

    if (cache == null) {
        debug("manager is null!");
        cache = new FileCache(cacheDir, max_zise, max_count);
        mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), cache);
    } else {/*from w  w w  . j a v  a 2  s .  c o m*/
        debug("manager is not null!");
    }
    return cache;
}