Example usage for java.net URL toString

List of usage examples for java.net URL toString

Introduction

In this page you can find the example usage for java.net URL toString.

Prototype

public String toString() 

Source Link

Document

Constructs a string representation of this URL .

Usage

From source file:com.emobc.android.utils.RetreiveFileContentTask.java

private HttpUriRequest createGetUriRequest(URL url) {
    HttpGet httpGet = new HttpGet(url.toString());
    return httpGet;
}

From source file:Main.java

public boolean importData(JComponent comp, Transferable t) {
    DataFlavor[] flavors = t.getTransferDataFlavors();
    System.out.println("Trying to import:" + t);
    for (int i = 0; i < flavors.length; i++) {
        DataFlavor flavor = flavors[i];
        try {/*  w  w w.jav  a 2s  .com*/
            if (flavor.equals(DataFlavor.javaFileListFlavor)) {
                System.out.println("importData: FileListFlavor");
                List l = (List) t.getTransferData(DataFlavor.javaFileListFlavor);
                Iterator iter = l.iterator();
                while (iter.hasNext()) {
                    File file = (File) iter.next();
                    System.out.println("GOT FILE: " + file.getCanonicalPath());
                }
                return true;
            } else if (flavor.equals(DataFlavor.stringFlavor)) {
                System.out.println("importData: String Flavor");
                String fileOrURL = (String) t.getTransferData(flavor);
                System.out.println("GOT STRING: " + fileOrURL);
                try {
                    URL url = new URL(fileOrURL);
                    System.out.println("Valid URL: " + url.toString());
                    return true;
                } catch (MalformedURLException ex) {
                    System.err.println("Not a valid URL");
                    return false;
                }
            } else {
                System.out.println("importData rejected: " + flavor);
            }
        } catch (IOException ex) {
            System.err.println("IOError getting data: " + ex);
        } catch (UnsupportedFlavorException e) {
            System.err.println("Unsupported Flavor: " + e);
        }
    }
    return false;
}

From source file:com.gallatinsystems.common.util.S3Util.java

public static boolean putObjectAcl(String bucketName, String objectKey, ACL acl, String awsAccessId,
        String awsSecretKey) throws IOException {

    final String date = getDate();
    final URL url = new URL(String.format(S3_URL, bucketName, objectKey) + "?acl");
    final String payload = String.format(PUT_PAYLOAD_ACL, date, acl.toString(), bucketName, objectKey);
    final String signature = MD5Util.generateHMAC(payload, awsSecretKey);
    HttpURLConnection conn = null;
    try {//  w  ww  .jav a 2s .c om

        conn = (HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestMethod("PUT");
        conn.setRequestProperty("Date", date);
        conn.setRequestProperty("x-amz-acl", acl.toString());
        conn.setRequestProperty("Authorization", "AWS " + awsAccessId + ":" + signature);

        int status = conn.getResponseCode();

        if (status != 200 && status != 201) {
            log.severe("Error setting ACL for: " + url.toString());
            log.severe(IOUtils.toString(conn.getInputStream()));
            return false;
        }
        return true;
    } finally {
        if (conn != null) {
            conn.disconnect();
        }
    }
}

From source file:gobblin.source.extractor.hadoop.HadoopFsHelperTest.java

@Test
public void testGetFileStreamSucceedsWithUncompressedFile() throws FileBasedHelperException, IOException {
    SourceState sourceState = new SourceState();
    URL rootUrl = getClass().getResource("/source/");
    String rootPath = rootUrl.toString();
    sourceState.setProp(ConfigurationKeys.SOURCE_FILEBASED_FS_URI, rootPath);
    HadoopFsHelper fsHelper = new HadoopFsHelper(sourceState);

    fsHelper.connect();/*from  ww w. j av  a  2  s.  c om*/
    URL url = getClass().getResource("/source/simple.tsv");
    String path = url.toString();
    InputStream in = fsHelper.getFileStream(path);
    String contents = IOUtils.toString(in, "UTF-8");
    Assert.assertEquals(contents, "A\t1\nB\t2\n");
}

From source file:gobblin.source.extractor.hadoop.HadoopFsHelperTest.java

@Test
public void testGetFileStreamSucceedsWithGZIPFile() throws FileBasedHelperException, IOException {
    SourceState sourceState = new SourceState();
    URL rootUrl = getClass().getResource("/source/");
    String rootPath = rootUrl.toString();
    sourceState.setProp(ConfigurationKeys.SOURCE_FILEBASED_FS_URI, rootPath);
    HadoopFsHelper fsHelper = new HadoopFsHelper(sourceState);

    fsHelper.connect();/*  w w  w  .  ja v  a2s .co m*/
    URL url = getClass().getResource("/source/simple.tsv.gz");
    String path = url.toString();
    InputStream in = fsHelper.getFileStream(path);
    String contents = IOUtils.toString(in, "UTF-8");
    Assert.assertEquals(contents, "A\t1\nB\t2\n");
}

From source file:com.opentable.config.TestNewstyleConfig.java

@Test
public void testNewstyle() throws Exception {
    final URL path = TestNewstyleConfig.class.getResource("/newstyle-config");
    final Config config = Config.getConfig(path.toString(), "common,common/test,app,app/test");
    final AbstractConfiguration props = config.getConfiguration();

    assertEquals("a", props.getString("prop1"));
    assertEquals("b", props.getString("prop2"));
    assertEquals("c", props.getString("prop3"));
    assertEquals("d", props.getString("prop4"));
}

From source file:com.quartzdesk.executor.common.spring.metadata.BuildPropertiesFactoryBean.java

@Override
protected Map<String, String> createInstance() throws Exception {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

    Enumeration<URL> resourceUrls = classLoader.getResources(propertiesPath);
    while (resourceUrls.hasMoreElements()) {
        URL resourceUrl = resourceUrls.nextElement();
        if (resourceUrl.toString().contains(moduleName)) {
            InputStream ins = null;
            try {
                ins = resourceUrl.openStream();
                return new UTF8Map(ins);
            } finally {
                IOUtils.close(ins);/* ww w . j a v  a  2 s  . c o  m*/
            }
        }
    }

    throw new IllegalStateException(
            "Build properties resource not found at: " + propertiesPath + ". Used module name: " + moduleName);
}

From source file:org.apache.metron.maas.util.RESTUtil.java

public URL appendToUrl(URL endpointUrl, String params) throws MalformedURLException {
    return new URL(endpointUrl.toString() + "?" + params);
}

From source file:com.w20e.socrates.workflow.ProcessorFactory.java

/**
 * Create processor based on URL holding config.
 * /*ww w.j a v a 2s.com*/
 * @param url
 *            a <code>String</code> value
 * @return a <code>Processor</code> value
 * @exception Exception
 *                if an error occurs
 */
public final Processor createProcessor(final URL url) throws Exception {

    return (Processor) this.dig.parse(url.toString());
}

From source file:com.emobc.android.utils.RetreiveFileContentTask.java

private HttpUriRequest createPostUriRequest(URL url) {
    HttpPost httppost = new HttpPost(url.toString());
    // Add your data
    try {//  w  w w . j  av  a 2  s.  com
        httppost.setEntity(new UrlEncodedFormEntity(parameters));
        return httppost;
    } catch (UnsupportedEncodingException e) {
    }
    return null;
}