Example usage for java.io File toString

List of usage examples for java.io File toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the pathname string of this abstract pathname.

Usage

From source file:Main.java

public static String compressGzipFile(String filename) {
    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {

        File flockedFilesFolder = new File(
                Environment.getExternalStorageDirectory() + File.separator + "FlockLoad");
        System.out.println("FlockedFileDir: " + flockedFilesFolder);
        String uncompressedFile = flockedFilesFolder.toString() + "/" + filename;
        String compressedFile = flockedFilesFolder.toString() + "/" + "gzip.zip";

        try {//from  w w w.  jav a2 s.c om
            FileInputStream fis = new FileInputStream(uncompressedFile);
            FileOutputStream fos = new FileOutputStream(compressedFile);
            GZIPOutputStream gzipOS = new GZIPOutputStream(fos) {
                {
                    def.setLevel(Deflater.BEST_COMPRESSION);
                }
            };

            byte[] buffer = new byte[1024];
            int len;
            while ((len = fis.read(buffer)) != -1) {
                gzipOS.write(buffer, 0, len);
            }
            //close resources
            gzipOS.close();
            fos.close();
            fis.close();
            return compressedFile;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return null;

}

From source file:Main.java

public static String zip(String filename) throws IOException {
    BufferedInputStream origin = null;
    Integer BUFFER_SIZE = 20480;/* w  w  w  .j  av  a2  s.c  o  m*/

    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {

        File flockedFilesFolder = new File(
                Environment.getExternalStorageDirectory() + File.separator + "FlockLoad");
        System.out.println("FlockedFileDir: " + flockedFilesFolder);
        String uncompressedFile = flockedFilesFolder.toString() + "/" + filename;
        String compressedFile = flockedFilesFolder.toString() + "/" + "flockZip.zip";
        ZipOutputStream out = new ZipOutputStream(
                new BufferedOutputStream(new FileOutputStream(compressedFile)));
        out.setLevel(9);
        try {
            byte data[] = new byte[BUFFER_SIZE];
            FileInputStream fi = new FileInputStream(uncompressedFile);
            System.out.println("Filename: " + uncompressedFile);
            System.out.println("Zipfile: " + compressedFile);
            origin = new BufferedInputStream(fi, BUFFER_SIZE);
            try {
                ZipEntry entry = new ZipEntry(
                        uncompressedFile.substring(uncompressedFile.lastIndexOf("/") + 1));
                out.putNextEntry(entry);
                int count;
                while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) {
                    out.write(data, 0, count);
                }
            } finally {
                origin.close();
            }
        } finally {
            out.close();
        }
        return "flockZip.zip";
    }
    return null;
}

From source file:com.microsoft.alm.plugin.external.tools.TfTool.java

/**
 * Checks if the given path contains one of the given acceptable tf commands
 *
 * @param exePath//from w  ww . jav a  2s.c o m
 * @param exeNames
 * @return
 */
private static String checkTfPath(final String exePath, final String[] exeNames) {
    if (StringUtils.isNotEmpty(exePath)) {
        for (final String filename : exeNames) {
            final File tfFile = new File(exePath, filename);
            if (tfFile.exists()) {
                return tfFile.toString();
            }
        }
    }
    return null;
}

From source file:io.fluo.metrics.config.Reporters.java

static List<AutoCloseable> startReporters(MetricRegistry registry, File yaml) throws Exception {
    ConfigurationSourceProvider csp = null;
    if (yaml.exists()) {
        csp = new FileConfigurationSourceProvider();
    }//from   w  w  w. ja v a 2 s.c o  m

    return startReporters(registry, csp, yaml.toString(), null);
}

From source file:com.microsoft.applicationinsights.internal.perfcounter.JniPCConnector.java

private static File buildDllLocalPath() {
    Properties properties = PropertyHelper.getSdkVersionProperties();
    if (properties == null) {
        throw new RuntimeException("Failed to find SDK Version Properties file.");
    }/*from   w  w  w. ja  va  2  s.  c o  m*/

    String version = properties.getProperty("version");
    if (version == null) {
        throw new RuntimeException("Failed to find SDK version.");
    }

    File dllPath = LocalFileSystemUtils.getTempDir();

    dllPath = new File(dllPath.toString(), AI_BASE_FOLDER);
    dllPath = new File(dllPath.toString(), AI_NATIVE_FOLDER);
    dllPath = new File(dllPath.toString(), version);

    if (!dllPath.exists()) {
        dllPath.mkdirs();
    }

    if (!dllPath.exists() || !dllPath.canRead() || !dllPath.canWrite()) {
        throw new RuntimeException("Failed to create a read/write folder for the native dll.");
    }

    InternalLogger.INSTANCE.trace("%s folder exists", dllPath.toString());

    return dllPath;
}

From source file:Main.java

public static File getCacheDirectory(Context context, boolean preferExternal, String dirName) {
    File appCacheDir = null;
    if (preferExternal && MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            && hasExternalStoragePermission(context)) {
        appCacheDir = getExternalCacheDir(context, dirName);
        Log.e("appCacheDir", appCacheDir.toString());
    }//from  w w  w  .  j  a  v  a  2  s.c o m
    if (appCacheDir == null) {
        appCacheDir = context.getCacheDir();
    }
    if (appCacheDir == null) {
        String cacheDirPath = "/data/data/" + context.getPackageName() + "/cache/";
        //Log.w("Can't define system cache directory! '%s' will be used.",cacheDirPath);
        appCacheDir = new File(cacheDirPath);
    }
    return appCacheDir;
}

From source file:biz.paluch.maven.configurator.FileTemplating.java

/**
 * Process files which match the template pattern. Creates a new file using the input file with property
 * replacement. Target filename is without the template name part.
 *
 * @param log/* ww w  . j a v a  2s . com*/
 * @param root
 * @param processor
 * @throws IOException
 */
public static void processFiles(Log log, File root, TemplateProcessor processor) throws IOException {

    Iterator<File> iterator = FileUtils.iterateFiles(root, new RegexFileFilter(FILE_TEMPLATE_PATTERN),
            TrueFileFilter.TRUE);

    while (iterator.hasNext()) {
        File next = iterator.next();
        log.debug("Processing file " + next);
        try {
            processor.processFile(next, getTargetFile(next));
        } catch (IOException e) {
            throw new IOException("Cannot process file " + next.toString() + ": " + e.getMessage(), e);
        }
    }
}

From source file:com.cloudera.sqoop.shims.ShimLoader.java

/**
 * Look through the shim directory for a jar matching 'jarPattern'
 * and classload it.//from  w  w  w . j a  v a2s .co  m
 * @param jarPattern a regular expression which the shim jar's filename
 * must match.
 * @param className a class to classload from the jar.
 */
private static void loadMatchingShimJar(String jarPattern, String className) throws IOException {
    String jarFilename;

    String shimDirName = System.getProperty(SHIM_JAR_DIR_PROPERTY, ".");
    File shimDir = new File(shimDirName);
    if (!shimDir.exists()) {
        throw new IOException("No such shim directory: " + shimDirName);
    }

    String[] candidates = shimDir.list();
    if (null == candidates) {
        throw new IOException("Could not list shim directory: " + shimDirName);
    }

    for (String candidate : candidates) {
        if (candidate.matches(jarPattern)) {
            LOG.debug("Found jar matching pattern " + jarPattern + ": " + candidate);
            File jarFile = new File(shimDir, candidate);
            String jarFileName = jarFile.toString();
            ClassLoaderStack.addJarFile(jarFileName, className);
            LOG.debug("Successfully pushed classloader for jar: " + jarFileName);
            return;
        }
    }

    throw new IOException("Could not load shim jar for pattern: " + jarPattern);
}

From source file:fi.johannes.kata.ocr.utils.files.CFileOperations.java

public static List<String> getFileContentAsStrings(File f) throws IOException {
    FileReader fr = new FileReader(f.toString());
    BufferedReader br = new BufferedReader(fr);
    List<String> res = getFileContentAsStrings(br);
    fr.close();//from   w  w  w  .j  a  v  a  2  s . c o  m
    return res;
}

From source file:mx.itesm.mexadl.metrics.util.Util.java

/**
 * Get the Java classes in the given directory, including those in
 * sub-directories./*from www  .java  2s  .  c  o m*/
 * 
 * @param directory
 * @return
 */
public static List<String> getClassesInDirectory(final File directory) {
    File currentFile;
    File[] directoryFiles;
    List<String> innerFiles;
    List<String> returnValue;

    returnValue = null;
    directoryFiles = directory.listFiles(new FileFilter() {
        @Override
        public boolean accept(final File pathname) {
            return (pathname.isDirectory() || pathname.toString().endsWith(".class"));
        }
    });

    if ((directoryFiles != null) && (directoryFiles.length > 0)) {
        returnValue = new ArrayList<String>();
        for (int i = 0; i < directoryFiles.length; i++) {
            currentFile = directoryFiles[i];

            if (currentFile.isDirectory()) {
                innerFiles = Util.getClassesInDirectory(currentFile);
                if (innerFiles != null) {
                    returnValue.addAll(innerFiles);
                }
            } else {
                returnValue.add(currentFile.getAbsolutePath());
            }
        }
    }

    return returnValue;
}