Example usage for java.io File toURL

List of usage examples for java.io File toURL

Introduction

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

Prototype

@Deprecated
public URL toURL() throws MalformedURLException 

Source Link

Document

Converts this abstract pathname into a file: URL.

Usage

From source file:com.jpeterson.littles3.bo.FileS3ObjectTest.java

/**
 * Test the content length property.//from   w w  w .j  av  a 2s  . co  m
 */
public void test_contentLength() {
    File file;
    FileS3Object s3Object;

    try {
        file = File.createTempFile("unitTest", null);

        file.deleteOnExit();

        FileOutputStream out = new FileOutputStream(file);

        out.write("12345".getBytes());

        out.close();

        s3Object = new FileS3Object("bucket", "key", file.toURL());

        assertEquals("Unexpected value", 5, s3Object.getContentLength());
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected exception");
        return;
    }
}

From source file:com.jpeterson.littles3.bo.FileS3ObjectTest.java

/**
 * Test the last modified property./*  w w w  .  ja v  a2s . c o m*/
 */
public void test_lastModified() {
    File file;
    FileS3Object s3Object;

    try {
        file = File.createTempFile("unitTest", null);

        file.deleteOnExit();

        FileOutputStream out = new FileOutputStream(file);

        out.write("12345".getBytes());

        out.close();

        s3Object = new FileS3Object("bucket", "key", file.toURL());

        assertEquals("Unexpected value", file.lastModified(), s3Object.getLastModified());
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected exception");
        return;
    }
}

From source file:MixedTest.java

public URL getWorkingDirectory() throws java.net.MalformedURLException {
    URL url = null;//from w ww . j  a  v a 2 s. c  o m

    try {
        File file = new File(System.getProperty("user.dir"));
        System.out.println("Running as Application:");
        System.out.println("   " + file.toURL());
        return file.toURL();
    } catch (Exception e) {
    }

    System.out.println("Running as Applet:");
    System.out.println("   " + getCodeBase());

    return getCodeBase();
}

From source file:org.basket3.filesystem.FileS3ObjectTest.java

/**
 * Test the delete data method./*from   ww  w.j a va  2  s  . c  o m*/
 */
public void test_deleteData() {
    File file;
    GAES3Object s3Object;

    try {
        file = File.createTempFile("unitTest", null);

        file.deleteOnExit();

        FileOutputStream out = new FileOutputStream(file);

        out.write("12345".getBytes());

        out.close();

        s3Object = new GAES3Object("bucket", "key", file.toURL());

        assertTrue("File should exits", file.exists());

        assertTrue("Should be able to delete", s3Object.deleteData());

        assertFalse("File should not exist", file.exists());

        assertFalse("Should already be deleted", s3Object.deleteData());
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected exception");
        return;
    }
}

From source file:org.basket3.filesystem.FileS3ObjectTest.java

/**
 * Test the input stream method./*  w w w  .  j  ava 2 s.  c  o  m*/
 */
public void test_inputStream() {
    File file;
    GAES3Object s3Object;

    try {
        file = File.createTempFile("unitTest", null);

        file.deleteOnExit();

        FileOutputStream out = new FileOutputStream(file);

        out.write("12345".getBytes());

        out.close();

        s3Object = new GAES3Object("bucket", "key", file.toURL());

        InputStream in = s3Object.getInputStream();

        assertEquals("Unexpected value", '1', in.read());
        assertEquals("Unexpected value", '2', in.read());
        assertEquals("Unexpected value", '3', in.read());
        assertEquals("Unexpected value", '4', in.read());
        assertEquals("Unexpected value", '5', in.read());
        assertEquals("Unexpected value", -1, in.read());
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected exception");
        return;
    }
}

From source file:com.jpeterson.littles3.bo.FileS3ObjectTest.java

/**
 * Test the delete data method.//from w ww  . j a v a  2s  .c  o  m
 */
public void test_deleteData() {
    File file;
    FileS3Object s3Object;

    try {
        file = File.createTempFile("unitTest", null);

        file.deleteOnExit();

        FileOutputStream out = new FileOutputStream(file);

        out.write("12345".getBytes());

        out.close();

        s3Object = new FileS3Object("bucket", "key", file.toURL());

        assertTrue("File should exits", file.exists());

        assertTrue("Should be able to delete", s3Object.deleteData());

        assertFalse("File should not exist", file.exists());

        assertFalse("Should already be deleted", s3Object.deleteData());
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected exception");
        return;
    }
}

From source file:com.jpeterson.littles3.bo.FileS3ObjectTest.java

/**
 * Test the input stream method.//from  w  w  w . j av a  2s  . c  om
 */
public void test_inputStream() {
    File file;
    FileS3Object s3Object;

    try {
        file = File.createTempFile("unitTest", null);

        file.deleteOnExit();

        FileOutputStream out = new FileOutputStream(file);

        out.write("12345".getBytes());

        out.close();

        s3Object = new FileS3Object("bucket", "key", file.toURL());

        InputStream in = s3Object.getInputStream();

        assertEquals("Unexpected value", '1', in.read());
        assertEquals("Unexpected value", '2', in.read());
        assertEquals("Unexpected value", '3', in.read());
        assertEquals("Unexpected value", '4', in.read());
        assertEquals("Unexpected value", '5', in.read());
        assertEquals("Unexpected value", -1, in.read());
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected exception");
        return;
    }
}

From source file:org.openspaces.pu.container.standalone.StandaloneProcessingUnitContainerProvider.java

private void addJarsLocation(File fileLocation, List<URL> urls, String dir) {
    File libLocation = new File(fileLocation, dir);
    if (libLocation.exists()) {
        File[] jarFiles = BootIOUtils.listFiles(libLocation);
        for (File jarFile : jarFiles) {
            if (logger.isDebugEnabled()) {
                logger.debug("Adding jar [" + jarFile.getAbsolutePath() + "] with pu directory location ["
                        + location + "] to classpath");
            }/*from   www.j  a v  a2 s  . c  om*/
            try {
                urls.add(jarFile.toURL());
            } catch (MalformedURLException e) {
                throw new CannotCreateContainerException(
                        "Failed to add jar file [" + jarFile.getAbsolutePath() + "] to classs loader", e);
            }
        }
    }
}

From source file:com.npower.common.plugins.DaemonControllerPlugIn.java

/**
 * Given a string, return a URL to a Filesystem resource of that name.
 * /*from ww  w .  j av a 2  s.  c  o  m*/
 * @param path
 *            a path to a file.
 * @return a URL identifying the resource in the in the file system.
 * @throws MalformedURLException
 * @throws FileNotFoundException
 */
protected URL getFileURL(String path) throws IOException {
    path = macro(System.getProperties(), path);
    File file = new File(path);
    return file.toURL();
}

From source file:org.apache.cocoon.environment.AbstractEnvironment.java

/**
 * Constructs the abstract environment//  www  . j a v a2  s  . c om
 */
public AbstractEnvironment(String uri, String view, File file, String action) throws MalformedURLException {
    this(uri, view, file.toURL().toExternalForm(), action);
}