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:edu.cornell.med.icb.iterators.TextFileLineIterator.java

/**
 * Create the object using a file./*from  w ww  . j a  v  a 2 s  . c o m*/
 * @param fileToRead the filename to read
 * @throws IOException error opening the file to read
 */
public TextFileLineIterator(final File fileToRead) throws IOException {
    this(fileToRead.toString().toLowerCase().endsWith(".gz")
            ? new GZIPInputStream(new FileInputStream(fileToRead))
            : new FileInputStream(fileToRead));
}

From source file:FileMonitor.java

/**
 * Remove the listener from the notification list.
 * //w w  w .j  av  a  2 s  .co m
 * @param listener
 *          the listener to be removed.
 */
public void removeFileChangeListener(FileChangeListener listener, File file) {
    FileMonitorTask task = timerEntries.remove(file.toString() + listener.hashCode());
    if (task != null) {
        task.cancel();
    }
}

From source file:SimpleFileBrowser.java

private void init() {
    shell.setText("File Browser");
    shell.setLayout(new GridLayout(1, true));

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Browse ...");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dialog = new DirectoryDialog(shell, SWT.NULL);
            String path = dialog.open();
            if (path != null) {

                File file = new File(path);
                if (file.isFile())
                    displayFiles(new String[] { file.toString() });
                else
                    displayFiles(file.list());

            }//from   ww w  .j  a  v a 2s.c  o m
        }
    });

    GridData gd = new GridData(GridData.FILL_BOTH);

    table = new Table(shell, SWT.MULTI);
    table.setLayoutData(gd);

    // creates an image registry and adds icons to the image registry.
    imageRegistry = new ImageRegistry();

    ImageDescriptor defaultIcon = ImageDescriptor.createFromFile(null, "java2s.gif");
    imageRegistry.put("default", defaultIcon);

    ImageDescriptor jarIcon = ImageDescriptor.createFromFile(null, "img/jar.gif");
    imageRegistry.put("jar", jarIcon);
}

From source file:com.photon.phresco.framework.param.impl.IosThemesBundleFilterImpl.java

private StringBuilder getResourcesPath(String rootModulePath, String subModuleName) throws PhrescoException {
    ProjectInfo info = Utility.getProjectInfo(rootModulePath, subModuleName);
    File srcFolderLocation = Utility.getSourceFolderLocation(info, rootModulePath, subModuleName);
    StringBuilder builder = new StringBuilder(srcFolderLocation.toString());
    builder.append(File.separator);
    builder.append("source");
    builder.append(File.separator);
    builder.append("Resources");

    return builder;
}

From source file:com.photon.phresco.framework.param.impl.Html5ThemesListImpl.java

private StringBuilder getResourcesPath(String rootModulePath, String subModuleName) throws PhrescoException {
    ProjectInfo info = Utility.getProjectInfo(rootModulePath, subModuleName);
    File srcFolderLocation = Utility.getSourceFolderLocation(info, rootModulePath, subModuleName);
    StringBuilder builder = new StringBuilder(srcFolderLocation.toString());
    builder.append(File.separator);
    builder.append("src");
    builder.append(File.separator);
    builder.append("main");
    builder.append(File.separator);
    builder.append("webapp");
    builder.append(File.separator);
    builder.append("themes");

    return builder;
}

From source file:edu.pitt.dbmi.facebase.hd.domain.InstructionsFiles.java

public InstructionsFiles(File sourceFileValue, File destinationFileValue,
        String relativePathToFileInArchiveValue) {
    log.debug("InstructionsFiles constructed with:");
    log.debug(sourceFileValue.toString() + destinationFileValue.toString() + relativePathToFileInArchiveValue);
    sourceFile = sourceFileValue;//from   ww  w  .j  a  v a 2s.  co  m
    destinationFile = destinationFileValue;
    relativePathToFileInArchive = relativePathToFileInArchiveValue;
}

From source file:com.blackducksoftware.integration.hub.detect.util.executable.ExecutableFinder.java

public String getExecutablePathOrOverride(final ExecutableType executableType, final boolean searchSystemPath,
        final File path, final String override) {
    return getExecutablePathOrOverride(executableType, searchSystemPath, path.toString(), override);
}

From source file:com.viddu.handlebars.HandlebarsMojo.java

/**
 * Compiles Handlebar template file.//from   w  w  w . j a v  a 2  s. co  m
 * 
 * @param inputFile : The uncompiled Handlebars template file
 * @return A compiled Handlebar template file
 * @throws IOException
 */
protected String compile(Scriptable globalScope, File inputFile) throws IOException {
    getLog().info("Compiling file:" + inputFile.toString());
    String sInputFile = HandlebarsFileUtil.getFileContents(inputFile);
    String fileNameWithoutExt = FilenameUtils.removeExtension(inputFile.getName());
    Context compileContext = Context.enter();
    Scriptable compileScope = compileContext.newObject(globalScope);
    compileScope.setParentScope(globalScope);
    compileScope.put("template", compileScope, sInputFile);
    Object result = compileContext.evaluateString(compileScope, "Handlebars.precompile(template);",
            "PreCompile", 0, null);
    String compiledTemplate = Context.toString(result);
    StringBuilder strb = new StringBuilder("(function(){"
            + "\n  var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\n"
            + "templates[\'").append(fileNameWithoutExt).append("\'] = template(").append(compiledTemplate)
                    .append(");\n}());");
    return strb.toString();
}

From source file:tw.idv.gasolin.pycontw2012.util.BitmapUtils.java

/**
 * Only call this method from the main (UI) thread. The
 * {@link OnFetchCompleteListener} callback be invoked on the UI thread, but
 * image fetching will be done in an {@link AsyncTask}.
 * //from w ww .ja  va2s .  com
 * @param cookie
 *            An arbitrary object that will be passed to the callback.
 */
public static void fetchImage(final Context context, final String url,
        final BitmapFactory.Options decodeOptions, final Object cookie,
        final OnFetchCompleteListener callback) {
    new AsyncTask<String, Void, Bitmap>() {
        @Override
        protected Bitmap doInBackground(String... params) {
            final String url = params[0];
            if (TextUtils.isEmpty(url)) {
                return null;
            }

            // First compute the cache key and cache file path for this URL
            File cacheFile = null;
            try {
                MessageDigest mDigest = MessageDigest.getInstance("SHA-1");
                mDigest.update(url.getBytes());
                final String cacheKey = bytesToHexString(mDigest.digest());
                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                    cacheFile = new File(Environment.getExternalStorageDirectory() + File.separator + "Android"
                            + File.separator + "data" + File.separator + context.getPackageName()
                            + File.separator + "cache" + File.separator + "bitmap_" + cacheKey + ".tmp");
                }
            } catch (NoSuchAlgorithmException e) {
                // Oh well, SHA-1 not available (weird), don't cache
                // bitmaps.
            }

            if (cacheFile != null && cacheFile.exists()) {
                Bitmap cachedBitmap = BitmapFactory.decodeFile(cacheFile.toString(), decodeOptions);
                if (cachedBitmap != null) {
                    return cachedBitmap;
                }
            }

            try {
                // TODO: check for HTTP caching headers
                final HttpClient httpClient = SyncService.getHttpClient(context.getApplicationContext());
                final HttpResponse resp = httpClient.execute(new HttpGet(url));
                final HttpEntity entity = resp.getEntity();

                final int statusCode = resp.getStatusLine().getStatusCode();
                if (statusCode != HttpStatus.SC_OK || entity == null) {
                    return null;
                }

                final byte[] respBytes = EntityUtils.toByteArray(entity);

                // Write response bytes to cache.
                if (cacheFile != null) {
                    try {
                        cacheFile.getParentFile().mkdirs();
                        cacheFile.createNewFile();
                        FileOutputStream fos = new FileOutputStream(cacheFile);
                        fos.write(respBytes);
                        fos.close();
                    } catch (FileNotFoundException e) {
                        Log.w(TAG, "Error writing to bitmap cache: " + cacheFile.toString(), e);
                    } catch (IOException e) {
                        Log.w(TAG, "Error writing to bitmap cache: " + cacheFile.toString(), e);
                    }
                }

                // Decode the bytes and return the bitmap.
                return BitmapFactory.decodeByteArray(respBytes, 0, respBytes.length, decodeOptions);
            } catch (Exception e) {
                Log.w(TAG, "Problem while loading image: " + e.toString(), e);
            }
            return null;
        }

        @Override
        protected void onPostExecute(Bitmap result) {
            callback.onFetchComplete(cookie, result);
        }
    }.execute(url);
}

From source file:com.shazam.fork.reporter.gradle.ForkJenkinsReportTask.java

@SuppressWarnings("ResultOfMethodCallIgnored")
private void createDir(File dir) {
    try {//from w w w  .  ja v  a  2s. com
        deleteDirectory(dir);
        dir.mkdirs();
    } catch (IOException e) {
        throw new GradleException("Could not create directory: " + dir.toString(), e);
    }
}