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:fi.marketing.list.ui.DashboardUI.java

private void openAFileChooser() {
    FileFilter ft = new FileNameExtensionFilter("Text Files", "txt");
    db.addChoosableFileFilter(ft);// w  ww  .jav a  2 s .  c  om
    int returnVal = db.showOpenDialog(this);

    if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
        java.io.File file = db.getSelectedFile();
        if (file.isFile()) {
            String file_name = file.toString();
            //InputStream is = getClass().getClassLoader().getResourceAsStream(file_name);
            //FileReader just = oper.fileReaderInputStream(is);
            String name = FilenameUtils.getName(file_name);
            jTextField1.setText(name);
        }
    }
}

From source file:com.chinamobile.bcbsp.bspstaff.StaffRunner.java

/**
 * Start to run a BSP staff./*from  www  .  ja  v a2s  .  com*/
 */
@Override
public void run() {
    try {
        String sep = System.getProperty("path.separator");
        File workDir = new File(new File(staff.getJobFile()).getParent(), "work");
        boolean isCreated = workDir.mkdirs();
        if (!isCreated) {
            LOG.debug("StaffRunner.workDir : " + workDir);
        }
        StringBuffer classPath = new StringBuffer();
        classPath.append(System.getProperty("java.class.path"));
        classPath.append(sep);
        if (Constants.USER_BC_BSP_JOB_TYPE_C.equals(this.conf.getJobType())) {
            String exe = conf.getJobExe();
            if (exe != null) {
                classPath.append(sep);
                classPath.append(exe);
                classPath.append(sep);
                classPath.append(workDir);
            }
        } else {
            String jar = conf.getJar();
            // if jar exists, it into workDir
            if (jar != null) {
                RunJar.unJar(new File(jar), workDir);
                File[] libs = new File(workDir, "lib").listFiles();
                if (libs != null) {
                    for (int i = 0; i < libs.length; i++) {
                        // add libs from jar to classpath
                        classPath.append(sep);
                        classPath.append(libs[i]);
                    }
                }
                classPath.append(sep);
                classPath.append(new File(workDir, "classes"));
                classPath.append(sep);
                classPath.append(workDir);
            }
        }
        // Build exec child jmv args.
        Vector<String> vargs = new Vector<String>();
        File jvm = new File(new File(System.getProperty("java.home"), "bin"), "java");
        vargs.add(jvm.toString());

        // bsp.child.java.opts
        String javaOpts = conf.getConf().get("bsp.child.java.opts", "-Xmx200m");
        javaOpts = javaOpts.replace("@taskid@", staff.getStaffID().toString());
        String[] javaOptsSplit = javaOpts.split(" ");
        for (int i = 0; i < javaOptsSplit.length; i++) {
            vargs.add(javaOptsSplit[i]);
        }

        // Add classpath.
        vargs.add("-classpath");
        vargs.add(classPath.toString());

        // Setup the log4j prop
        long logSize = StaffLog.getStaffLogLength(((BSPConfiguration) conf.getConf()));
        vargs.add("-Dbcbsp.log.dir=" + new File(System.getProperty("bcbsp.log.dir")).getAbsolutePath());
        vargs.add("-Dbcbsp.root.logger=INFO,TLA");

        LOG.info("debug: staff ID is " + staff.getStaffID());

        vargs.add("-Dbcbsp.tasklog.taskid=" + staff.getStaffID());
        vargs.add("-Dbcbsp.tasklog.totalLogFileSize=" + logSize);

        // Add main class and its arguments
        vargs.add(WorkerManager.Child.class.getName());
        InetSocketAddress addr = workerManager.getStaffTrackerReportAddress();

        vargs.add(addr.getHostName());
        vargs.add(Integer.toString(addr.getPort()));
        vargs.add(staff.getStaffID().toString());
        vargs.add(Integer.toString(getFaultSSStep()));
        vargs.add(workerManager.getHostName());
        vargs.add(this.conf.getJobType());

        // Run java
        runChild(vargs.toArray(new String[0]), workDir);
    } catch (Exception e) {
        LOG.error("[run]", e);
    }
}

From source file:edu.unc.lib.dl.services.BatchIngestQueue.java

public boolean add(File prepDir) {
    IngestProperties props = null;//from w  w  w. j av  a2  s .c om
    try {
        props = new IngestProperties(prepDir);
    } catch (Exception e) {
        LOG.error(e);
        return false;
    }
    File result = new File(this.queuedDirectory, System.currentTimeMillis() + "-" + props.getSubmitter());
    if (result.exists()) {
        LOG.error("queued directory name conflict: " + result.toString());
        return false;
    }
    try {
        FileUtils.renameOrMoveTo(prepDir, result);
        File readyFile = new File(result, READY_FILE);
        readyFile.createNewFile();
    } catch (IOException e) {
        LOG.error(e);
        return false;
    }
    return true;
}

From source file:filesscanner.MainWindow.java

private void checkDirectory(File[] files) {

    int i = 0;/*from   w w  w .  jav a2 s . c  o  m*/
    for (File file1 : files) {

        if (file1.isDirectory()) {
            checkDirectory(file1.listFiles());
        }

        if (file1.toString().contains("mp3")) {
            System.out.println(file1);
            modelFiles.add(i, file1.toString());
            i++;
        }
    }

}

From source file:com.glluch.profilesparser.ProfileHtmlReader.java

@Override
public ArrayList<ICTProfile> readerDir(String dirname) {
    ArrayList<ICTProfile> profiles = new ArrayList<>();
    File dir = new File(dirname);

    File[] jobs = dir.listFiles();
    //System.out.println("jobs value="+Arrays.toString(jobs));
    for (File job : jobs) {
        //System.out.println(job+", value="+job.toString());
        profiles.add(this.reader(job.toString()));
    }//w  ww  . j a  v a  2  s  . c  o  m
    return profiles;
}

From source file:com.ikanow.aleph2.analytics.services.TestAnalyticsContext_FileSystemChecks.java

public void createDirs(File f, List<String> dirs) {
    dirs.stream().forEach(dir -> {/*from  www  .j  a v  a  2s  .c o m*/
        try {
            final File dir_obj = new File(f.toString() + "/" + dir);
            FileUtils.deleteDirectory(dir_obj);
            FileUtils.forceMkdir(dir_obj);

            //DEBUG
            //System.out.println("CREATED " + new File(f.toString() + "/" + dir));
        } catch (Exception e) {
            //DEBUG
            //e.printStackTrace();
        }
    });
}

From source file:de.u808.simpleinquest.indexer.impl.AbstractIndexer.java

public Document indexFile(File file) throws FileNotFoundException {
    this.file = file;
    this.document = FileDocument.Document(file);
    try {/*  w ww .  ja v  a 2 s .c o m*/
        this.setContentsFild(file);
    } catch (IndexerException ie) {
        log.error(ie.getMessage());
    } catch (Exception e) {
        log.error("Exception while fetch content of file: " + file.toString(), e);
        if (this.document != null) {
            List<Field> fields = this.document.getFields();
            if (fields != null) {
                for (Field f : fields) {
                    document.removeField(f.name());
                }
            }
            this.document = null;
        }
    } finally {
        this.file = null;
    }
    return document;
}

From source file:com.bluedragon.platform.java.JavaFileIO.java

public JavaFileIO(ServletConfig config) throws ServletException {

    try {/*from   w w  w .j a v  a 2s.c o  m*/
        fsManager = VFS.getManager();
        ((StandardFileSystemManager) fsManager).addProvider("s3",
                new com.intridea.io.vfs.provider.s3.S3FileProvider());
        ((StandardFileSystemManager) fsManager).addOperationProvider("s3",
                new com.intridea.io.vfs.provider.s3.acl.AclOperationsProvider());
    } catch (Exception e1) {
        cfEngine.log("Failed to register the s3:// name space: " + e1.getMessage());
    }

    // Set the working directory
    try {
        if (!setWorkingDirectory(config.getInitParameter("BLUEDRAGON_WORKING_DIRECTORY"))) {
            throw new Exception(
                    config.getInitParameter("BLUEDRAGON_WORKING_DIRECTORY") + " could not be created");
        }
    } catch (Exception E) {
        System.out.println(cfEngine.PRODUCT_NAME + ": Init Parameter BLUEDRAGON_WORKING_DIRECTORY Error: " + E);
        throw new ServletException(
                cfEngine.PRODUCT_NAME + ": Init Parameter BLUEDRAGON_WORKING_DIRECTORY Error: " + E);
    }

    // Setup the logging
    com.nary.Debug.SystemOff();
    File logFile = new File(getWorkingDirectory(), "bluedragon.log");
    rolloverLogFile(logFile);
    com.nary.Debug.setFilename(logFile.toString());

    setTempDirectory();
    setupRuntimeLogging();

    cfEngine.log(cfEngine.PRODUCT_NAME + " WorkingDirectory=[" + getWorkingDirectory() + "]");
    cfEngine.log(cfEngine.PRODUCT_NAME + " TempDirectory=[" + getTempDirectory() + "]");
}

From source file:Hash.Hash.java

public static String getHash(File file) throws FileNotFoundException, IOException {
    MessageDigest md5Digest = null;
    try {//ww w . jav  a 2 s .  co  m
        md5Digest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException ex) {
        return EMPTYHASH;
    }
    byte[] digestDef = md5Digest.digest();
    byte[] digest = null;
    String ext = FilenameUtils.getExtension(file.getName().toLowerCase());
    if (ext.equals("arw") || ext.equals("nef") || ext.equals("dng") || ext.equals("tif")
            || ext.equals("tiff")) {
        // <editor-fold defaultstate="collapsed" desc="raw">
        try (BufferedInputStream rawIn = new BufferedInputStream(new FileInputStream(file.toString()));) {
            digest = startOfScanTiff(file, rawIn);
        } catch (IOException e) {
            errorOut("Hash", e);
        }
        // </editor-fold>            
    } else {
        try (FileInputStream fileInStream = new FileInputStream(file.toString());
                BufferedInputStream fileStream = new BufferedInputStream(fileInStream);
                DigestInputStream in = new DigestInputStream(fileStream, md5Digest);) {
            byte[] buffer = new byte[4096];
            long length;
            switch (ext) {
            // <editor-fold defaultstate="collapsed" desc="mp4">
            case "mp4":
                in.on(false);
                boolean EOF = false;
                do {
                    length = readEndianValue(in, 4, false) - 8;
                    //                        byte boxLength[] = readBytes(in, 4);
                    String desc = new String(readBytes(in, 4));
                    //                        ByteBuffer wrapped = ByteBuffer.wrap(boxLength); // big-endian by default
                    //                        length = wrapped.getInt() - 8;
                    if (length == -7) {
                        //largesize
                        length = readEndianValue(in, 8, false) - 16;
                    } else if (length == -8) {
                        // until eof
                        EOF = true;
                    } else if (length == in.available()) {
                        EOF = true;
                    }
                    if (desc.equals("mdat")) {
                        in.on(true);
                        while (buffer.length <= length) {
                            int read = in.read(buffer);
                            length -= read;
                        }
                        while (length > 0) {
                            int read = in.read(buffer, 0, (int) length);
                            if (read == -1) {
                                digest = null;
                                break;
                            }
                            length -= read;
                        }
                        //                            break;
                    } else {
                        if (!skipBytes(in, length))
                            break;
                    }
                } while (!EOF);
                digest = md5Digest.digest();
                break;
            // </editor-fold>
            // <editor-fold defaultstate="collapsed" desc="JPG">
            case "jpg":
            case "jpeg":
                int scanLength;
                int scanLengthOld = 0;
                do {
                    in.on(false);
                    md5Digest.reset();
                    scanLength = 0;
                    if (startOfScanJPG(fileStream) == -1)
                        break;
                    in.on(true);
                    int c = 0;
                    int oldc;
                    do {
                        oldc = c;
                        c = in.read();
                        if (c == -1) {
                            return EMPTYHASH;
                        }
                        scanLength++;
                    } while (!(oldc == 0xFF && c == 0xD9/*217*/));
                    if (scanLength > scanLengthOld) {
                        digest = md5Digest.digest();
                        scanLengthOld = scanLength;
                    }
                } while (scanLengthOld < in.available());
                break;
            // </editor-fold>
            default:
                in.on(true);
                while (in.read(buffer) != -1) {
                }
                digest = md5Digest.digest();
                break;
            }
        } catch (IOException e) {
            errorOut("Hash", e);
        }
    }
    if (digest == null) {
        return EMPTYHASH;
    }
    if (Arrays.equals(digest, digestDef)) {
        return EMPTYHASH;
    }
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < digest.length; ++i) {
        sb.append(Integer.toHexString((digest[i] & 0xFF) | 0x100).substring(1, 3));
    }
    return sb.toString();
}

From source file:com.retroduction.carma.resolvers.util.TestCaseInstantiationVerifier.java

Set<URL> filterInvalidURLs(Set<File> classPathEntries) {

    Set<URL> result = new HashSet<URL>();

    if (classPathEntries != null) {
        for (File file : classPathEntries) {
            if (file != null) {
                try {
                    result.add(file.toURL());
                } catch (MalformedURLException e) {
                    this.log.warn("Invalid class path entry: " + file.toString());
                }/*from   w w w .  j  a  v a 2s.  com*/
            }
        }
    }
    return result;
}