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:com.symbian.driver.core.controller.utils.ModelUtils.java

/**
 * Subsitutes the variables, ${platform}, ${build}, ${epocroot}, ${repositoryroot}, ${resultroot} and
 * ${sourceroot} in a path./*from   ww w . ja  va  2 s .c  o m*/
 * 
 * @param aPath
 *            The path to check and subsitute the variables.
 * @param aTask 
 * @return The path with the subistituted variables for the actual values.
 * @throws ParseException 
 */
public static final String subsituteVariables(String aPath, Task aTask) {
    if (aPath != null) {
        try {
            aPath = aPath.replaceAll("\\$\\{platform\\}",
                    TDConfig.getInstance().getPreference(TDConfig.PLATFORM));
            aPath = aPath.replaceAll("\\$\\{build\\}", TDConfig.getInstance().getPreference(TDConfig.VARIANT));
            aPath = aPath.replaceAll("\\$\\{epocroot\\}",
                    (TDConfig.getInstance().getPreferenceFile(TDConfig.EPOC_ROOT).toString() + File.separator)
                            .replaceAll("\\\\", "\\\\\\\\"));
            aPath = aPath.replaceAll("\\$\\{sourceroot\\}",
                    (TDConfig.getInstance().getPreferenceFile(TDConfig.SOURCE_ROOT).toString() + File.separator)
                            .replaceAll("\\\\", "\\\\\\\\"));
            aPath = aPath.replaceAll("\\$\\{xmlroot\\}",
                    (TDConfig.getInstance().getPreferenceFile(TDConfig.XML_ROOT).toString() + File.separator)
                            .replaceAll("\\\\", "\\\\\\\\"));
            aPath = aPath.replaceAll("\\$\\{repositoryroot\\}",
                    (TDConfig.getInstance().getPreferenceFile(TDConfig.REPOSITORY_ROOT).toString()
                            + File.separator).replaceAll("\\\\", "\\\\\\\\"));

            if (aTask == null) {
                aPath = aPath.replaceAll("\\$\\{resultroot\\}",
                        (TDConfig.getInstance().getPreferenceFile(TDConfig.RESULT_ROOT).toString()
                                + File.separator).replaceAll("\\\\", "\\\\\\\\"));
            } else {
                File lPCResultPath = new File(TDConfig.getInstance().getPreferenceFile(TDConfig.RESULT_ROOT),
                        getBaseDirectory(aTask,
                                TDConfig.getInstance().getPreferenceInteger(TDConfig.RUN_NUMBER))
                                + File.separator);

                aPath = aPath.replaceAll("\\$\\{resultroot\\}",
                        lPCResultPath.toString().replaceAll("\\\\", "\\\\\\\\"));
            }

        } catch (ParseException lParseException) {
            ControllerUtils.LOGGER.log(Level.WARNING,
                    "Could not get the configuration while subsituting variables in a path.", lParseException);
        }
    }
    aPath = aPath.replaceAll("\\\\+", "\\\\");
    return aPath;
}

From source file:org.hupo.psi.mi.psicquic.ws.IndexBasedPsicquicRestServiceTest.java

@BeforeClass
public static void beforeClass() throws Exception {
    File indexDir = new File("target", "brca-mitab.index");

    Searcher.buildIndex(indexDir,/*w  w  w  .  j a v  a 2 s . c  o m*/
            IndexBasedPsicquicServiceTest.class.getResourceAsStream("/META-INF/brca2.mitab.txt"), true, true);
    Searcher.buildIndex(indexDir,
            IndexBasedPsicquicServiceTest.class.getResourceAsStream("/META-INF/400.mitab.txt"), false, true);

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "/META-INF/beans.spring.test.xml" });
    PsicquicConfig config = (PsicquicConfig) context.getBean("psicquicConfig");
    config.setIndexDirectory(indexDir.toString());

    service = (IndexBasedPsicquicRestService) context.getBean("indexBasedPsicquicRestService");
}

From source file:eu.qualimaster.dataManagement.storage.hdfs.HdfsUtils.java

/**
 * Transparently copies <code>source</code> to <code>target</code> in HDFS or DFS.
 * /*from   w w  w . ja  va 2 s .  c  o m*/
 * @param source the source file
 * @param target the target file
 * @param targetBase shell target be considered as the base path in HDFS or shall the Dfs path be prefixed
 * @return the target path used 
 * @throws IOException in case that copying fails
 */
public static String copy(File source, File target, boolean absolute) throws IOException {
    String result;
    if (!DataManagementConfiguration.isEmpty(DataManagementConfiguration.getHdfsUrl())) {
        String basePath = absolute ? target + "/"
                : DataManagementConfiguration.getDfsPath() + "/" + target + "/";
        FileSystem fs = HdfsUtils.getFilesystem();
        copy(fs, basePath, source);
        result = basePath;
    } else if (!DataManagementConfiguration.isEmpty(DataManagementConfiguration.getDfsPath())) {
        File tgt = new File(DataManagementConfiguration.getDfsPath(), target.toString());
        FileUtils.copyDirectory(source, tgt);
        result = tgt.getAbsolutePath();
    } else {
        throw new IOException("Cannot copy directory. Check HDFS/DFS configuration.");
    }
    return result;
}

From source file:org.meshpoint.anode.util.ModuleUtils.java

public static boolean copyFile(File src, File dest) {
    boolean result = true;
    if (src.isDirectory()) {
        result = copyDir(src, dest);// www  .  j av  a 2 s .c om
    } else {
        try {
            int count;
            byte[] buf = new byte[1024];
            FileInputStream fis = new FileInputStream(src);
            FileOutputStream fos = new FileOutputStream(dest);
            while ((count = fis.read(buf, 0, 1024)) != -1)
                fos.write(buf, 0, count);
        } catch (IOException e) {
            Log.v(TAG, "moveFile exception: aborting; exception: " + e + "; src = " + src.toString()
                    + "; dest = " + dest.toString());
            return false;
        }
    }
    return result;
}

From source file:edu.cmu.cs.lti.util.general.BasicConvenience.java

/**
 * Returns a reader for the specified file using the specified encoding. Any characters in the
 * input that are malformed or invalid for that encoding are replaced with the specified
 * substitution string./*w w  w .j  a va2 s .c om*/
 * 
 * @param f
 * @param encoding
 * @param substitution
 * @return
 * @throws FileNotFoundException
 */
public static BufferedReader getEncodingSafeBufferedReader(File f, String encoding, String substitution)
        throws FileNotFoundException {
    BufferedReader cin;
    Charset cs = Charset.forName(encoding);
    CharsetDecoder decoder = cs.newDecoder();
    decoder.onMalformedInput(CodingErrorAction.REPLACE);
    decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
    decoder.replaceWith(substitution);

    InputStream is = new FileInputStream(f);
    if (f.toString().endsWith(".zip"))
        is = new ZipInputStream(is);

    cin = new BufferedReader(new InputStreamReader(is, decoder));
    return cin;
}

From source file:net.rim.ejde.internal.builders.ResourceBuilder.java

private static synchronized String getTemporaryWorkingDir() {
    String tmpDir = System.getProperty("java.io.tmpdir");
    if (tmpDir == null) {
        // Shouldn't happen
        tmpDir = ".";
    }//from  w  ww .j  a v  a2 s  . c  o  m

    File subDir = null;

    for (int retry = 0; retry < 10; retry++) {
        subDir = new File(tmpDir,
                RESOURCE_BUILD_TMP_FOLDER_HEAD + System.currentTimeMillis() + ConvertUtil.ext_dir);
        if (!subDir.exists() && subDir.mkdir()) {
            return subDir.toString();
        }
    }

    throw new RuntimeException("unable to create temporary subdirectory: " + subDir.getPath());
}

From source file:fi.mikuz.boarder.util.FileProcessor.java

public static GraphicalSoundboardHolder loadUnlimitedSoundboardBoard(File boardDir, String boardName)
        throws IOException {
    GraphicalSoundboardHolder holder = new GraphicalSoundboardHolder();
    GraphicalSoundboard gsb = new GraphicalSoundboard();

    DataInputStream in = new DataInputStream(new FileInputStream(boardDir + "/graphicalBoard"));
    BufferedReader br = new BufferedReader(new InputStreamReader(in), 8192);

    String line;/*from   w w w  . j  a v a  2s.co  m*/
    line = br.readLine();

    gsb.setPlaySimultaneously(Boolean.parseBoolean(line.substring(0, line.indexOf("1"))));
    gsb.setBoardVolume(
            Float.valueOf(line.substring(line.indexOf("1") + 3, line.indexOf("2"))).floatValue());
    gsb.setUseBackgroundImage(
            Boolean.parseBoolean(line.substring(line.indexOf("2") + 3, line.indexOf("3"))));
    gsb.setBackgroundColor(
            Integer.valueOf(line.substring(line.indexOf("3") + 3, line.indexOf("4"))).intValue());
    File backgroundImagePath = new File(line.substring(line.indexOf("4") + 3, line.indexOf("5")));
    if (backgroundImagePath.toString().contains("local/")) {
        backgroundImagePath = new File(SoundboardMenu.mSbDir + "/" + boardName,
                backgroundImagePath.toString().substring(6, backgroundImagePath.toString().length()));
    } else if (backgroundImagePath.toString().equals("na")) {
        backgroundImagePath = null;
    }
    gsb.setBackgroundImagePath(backgroundImagePath);
    gsb.setBackgroundX(
            Float.valueOf(line.substring(line.indexOf("5") + 3, line.indexOf("6"))).floatValue());
    gsb.setBackgroundY(
            Float.valueOf(line.substring(line.indexOf("6") + 3, line.indexOf("7"))).floatValue());
    gsb.setBackgroundWidthHeight(null,
            Float.valueOf(line.substring(line.indexOf("7") + 3, line.indexOf("8"))).floatValue(),
            Float.valueOf(line.substring(line.indexOf("8") + 3, line.indexOf("9"))).floatValue());
    gsb.setScreenOrientation(
            Integer.valueOf(line.substring(line.indexOf("9") + 3, line.indexOf("10"))).intValue());
    gsb.setAutoArrange(Boolean.parseBoolean(line.substring(line.indexOf("10") + 4, line.indexOf("11"))));
    gsb.setAutoArrangeColumns(
            Integer.valueOf(line.substring(line.indexOf("11") + 4, line.indexOf("12"))).intValue());
    gsb.setAutoArrangeRows(Integer.valueOf(line.substring(line.indexOf("12") + 4, line.length())).intValue());

    while ((line = br.readLine()) != null) {
        GraphicalSound sound = new GraphicalSound();

        sound.setName(line.substring(0, line.indexOf("1")).replaceAll("lineBreak", "\n"));

        File soundPath = new File(line.substring(line.indexOf("1") + 3, line.indexOf("2")));
        if (soundPath.toString().contains("local/")) {
            sound.setPath(new File(SoundboardMenu.mSbDir + "/" + boardName,
                    soundPath.toString().substring(6, soundPath.toString().length())));
        } else {
            sound.setPath(soundPath);
        }

        sound.setVolumeLeft(
                Float.valueOf(line.substring(line.indexOf("2") + 3, line.indexOf("3"))).floatValue());
        sound.setVolumeRight(
                Float.valueOf(line.substring(line.indexOf("3") + 3, line.indexOf("4"))).floatValue());
        sound.setNameFrameX(
                Float.valueOf(line.substring(line.indexOf("4") + 3, line.indexOf("5"))).floatValue());
        sound.setNameFrameY(
                Float.valueOf(line.substring(line.indexOf("5") + 3, line.indexOf("6"))).floatValue());
        sound.setHideImageOrText(Integer.valueOf(line.substring(line.indexOf("8") + 3, line.indexOf("9"))));

        File imagePath = new File(line.substring(line.indexOf("9") + 3, line.indexOf("10")));
        if (imagePath.toString().contains("local/")) {
            sound.setImagePath(new File(SoundboardMenu.mSbDir + "/" + boardName,
                    imagePath.toString().substring(6, imagePath.toString().length())));
        } else {
            sound.setImagePath(imagePath);
        }

        sound.setImageX(
                Float.valueOf(line.substring(line.indexOf("10") + 4, line.indexOf("11"))).floatValue());
        sound.setImageY(
                Float.valueOf(line.substring(line.indexOf("11") + 4, line.indexOf("12"))).floatValue());
        sound.setImageWidthHeight(null,
                Float.valueOf(line.substring(line.indexOf("12") + 4, line.indexOf("13"))).floatValue(),
                Float.valueOf(line.substring(line.indexOf("13") + 4, line.indexOf("14"))).floatValue());
        sound.setHideImageOrText(
                Integer.valueOf(line.substring(line.indexOf("14") + 4, line.indexOf("15"))));
        sound.setNameTextColorInt(
                Integer.valueOf(line.substring(line.indexOf("15") + 4, line.indexOf("16"))));
        sound.setNameFrameInnerColorInt(
                Integer.valueOf(line.substring(line.indexOf("16") + 4, line.indexOf("17"))));
        sound.setNameFrameBorderColorInt(
                Integer.valueOf(line.substring(line.indexOf("17") + 4, line.indexOf("18"))));
        sound.setShowNameFrameInnerPaint(
                Boolean.parseBoolean(line.substring(line.indexOf("18") + 4, line.indexOf("19"))));
        sound.setShowNameFrameBorderPaint(
                Boolean.parseBoolean(line.substring(line.indexOf("19") + 4, line.indexOf("20"))));
        sound.setLinkNameAndImage(
                Boolean.parseBoolean(line.substring(line.indexOf("20") + 4, line.indexOf("21"))));
        sound.setNameSize(Float.valueOf(line.substring(line.indexOf("21") + 4, line.indexOf("22"))));
        sound.setAutoArrangeColumn(
                Integer.valueOf(line.substring(line.indexOf("22") + 4, line.indexOf("23"))));
        sound.setAutoArrangeRow(
                Integer.valueOf(line.substring(line.indexOf("23") + 4, line.indexOf("24"))));

        File activeImagePath = new File(line.substring(line.indexOf("24") + 4, line.indexOf("25")));
        if (activeImagePath.toString().contains("local/")) {
            sound.setActiveImagePath(new File(SoundboardMenu.mSbDir + "/" + boardName,
                    activeImagePath.toString().substring(6, activeImagePath.toString().length())));
        } else {
            sound.setActiveImagePath(activeImagePath);
        }
        sound.setSecondClickAction(Integer.valueOf(line.substring(line.indexOf("25") + 4, line.length())));

        if (sound.getImagePath().getAbsolutePath().equals("/"))
            sound.setImagePath(null);
        if (sound.getActiveImagePath().getAbsolutePath().equals("/"))
            sound.setActiveImagePath(null);

        gsb.addSound(sound);
    }

    in.close();
    holder.getBoardList().add(gsb);

    return holder;
}

From source file:com.hernandez.rey.crypto.TripleDES.java

/**
 * Save the specified TripleDES SecretKey to the specified file
 * /*from  w  w w.  ja va 2s  .  c om*/
 * @param key the key to write
 * @param keyFile
 * @throws IOException
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeySpecException
 */
public static void writeKey(final SecretKey key, final File keyFile)
        throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
    // Convert the secret key to an array of bytes like this
    final SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("DESede");
    final DESedeKeySpec keyspec = (DESedeKeySpec) keyfactory.getKeySpec(key, DESedeKeySpec.class);
    final byte[] rawkey = keyspec.getKey();

    final byte[] encodedKey = Base64.encodeBase64(rawkey);

    // Write the raw key to the file
    FileOutputStream out = new FileOutputStream(keyFile);
    out.write(encodedKey);
    out.close();

    out = new FileOutputStream(new File(keyFile.toString().concat("-raw")));
    out.write(rawkey);
    out.close();
}

From source file:net.metanotion.sqlc.SQLC.java

public static void treewalk(final ClassInfo ir, final File folder, final Iterable<String> srcPathes)
        throws Exception {
    for (final File file : folder.listFiles()) {
        if (file.isFile()) {
            final String sqlFileName = file.toString();
            final int len = sqlFileName.length();
            if ((len > 4) && (".sql".equals(sqlFileName.substring(len - 4, len).toLowerCase()))) {
                try {
                    processFile(ir, sqlFileName, srcPathes);
                } catch (ParseException pe) {
                    logger.debug("Error in file {}", sqlFileName);
                    throw pe;
                }/*w  w w  . j a  v a2  s . com*/
            }
        } else if (file.isDirectory()) {
            treewalk(ir, file, srcPathes);
        }
    }
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java

public static void createThumnail(File file) {
    String name = file.getName();
    String filePath = file.getAbsolutePath();
    Bitmap bm;//  w  ww .  j  a va  2 s  .  co  m

    if ((file.toString().contains(ConstantKeys.EXTENSION_JPG))
            || (file.toString().contains(ConstantKeys.EXTENSION_PNG))
            || (file.toString().contains(ConstantKeys.EXTENSION_JPEG))) {
        bm = decodeSampledBitmapFromPath(filePath, 250, 250);
        name = name.replace(ConstantKeys.EXTENSION_JPG, ConstantKeys.STRING_DEFAULT);

    } else {
        bm = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Images.Thumbnails.MINI_KIND);
        name = name.replace(ConstantKeys.EXTENSION_3GP, ConstantKeys.STRING_DEFAULT);

    }

    if (bm == null) {
        log.error("Error creating thumbnail");
        return;
    }

    File f = new File(getDir(), name + ConstantKeys.THUMBNAIL + ConstantKeys.EXTENSION_JPG);
    try {
        f.createNewFile();
    } catch (IOException e1) {
        log.error("Error creating file for thumbnail", e1);
        return;
    }
    // Convert bitmap to byte array
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bm.compress(CompressFormat.PNG, 0, bos);
    byte[] bitmapdata = bos.toByteArray();
    // write the bytes in file
    FileOutputStream fos;
    try {
        fos = new FileOutputStream(f);
        fos.write(bitmapdata);
        fos.flush();
        fos.close();
    } catch (Exception e) {
        log.debug("Error creagint thumnail", e);
    }

    bm = null;
    System.gc();
}