List of usage examples for java.net URL getContent
public final Object getContent() throws java.io.IOException
From source file:com.emc.atmos.api.test.AtmosApiClientTest.java
@Test public void testGetShareableUrlAndDisposition() throws Exception { Assume.assumeFalse(isVipr);/*from w ww. j ava 2 s. c om*/ // Create an object with content. String str = "Four score and twenty years ago"; ObjectId id = this.api.createObject(str.getBytes("UTF-8"), "text/plain"); Assert.assertNotNull("null ID returned", id); cleanup.add(id); String disposition = "attachment; filename=\"foo bar.txt\""; Calendar c = Calendar.getInstance(); c.add(Calendar.HOUR, 4); Date expiration = c.getTime(); URL u = this.api.getShareableUrl(id, expiration, disposition); l4j.debug("Sharable URL: " + u); InputStream stream = (InputStream) u.getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(stream)); String content = br.readLine(); l4j.debug("Content: " + content); Assert.assertEquals("URL does not contain proper content", str, content); }
From source file:com.emc.atmos.api.test.AtmosApiClientTest.java
@Test public void testGetShareableUrlWithPathAndDisposition() throws Exception { Assume.assumeFalse(isVipr);// www.ja va 2 s .c o m // Create an object with content. String str = "Four score and twenty years ago"; ObjectPath op = new ObjectPath("/" + rand8char() + ".txt"); ObjectId id = this.api.createObject(op, str.getBytes("UTF-8"), "text/plain"); Assert.assertNotNull("null ID returned", id); //cleanup.add( op ); String disposition = "attachment; filename=\"foo bar.txt\""; Calendar c = Calendar.getInstance(); c.add(Calendar.HOUR, 4); Date expiration = c.getTime(); URL u = this.api.getShareableUrl(op, expiration, disposition); l4j.debug("Sharable URL: " + u); InputStream stream = (InputStream) u.getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(stream)); String content = br.readLine(); l4j.debug("Content: " + content); Assert.assertEquals("URL does not contain proper content", str, content); }
From source file:com.emc.atmos.api.test.AtmosApiClientTest.java
@Test public void testExpiredSharableUrl() throws Exception { Assume.assumeFalse(isVipr);/*ww w . j a v a 2 s .c o m*/ // Create an object with content. String str = "Four score and twenty years ago"; ObjectId id = this.api.createObject(str.getBytes("UTF-8"), "text/plain"); Assert.assertNotNull("null ID returned", id); cleanup.add(id); Calendar c = Calendar.getInstance(); c.add(Calendar.HOUR, -4); Date expiration = c.getTime(); URL u = api.getShareableUrl(id, expiration); l4j.debug("Sharable URL: " + u); try { InputStream stream = (InputStream) u.getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(stream)); String content = br.readLine(); l4j.debug("Content: " + content); Assert.fail("Request should have failed"); } catch (Exception e) { l4j.debug("Error (expected): " + e); } }
From source file:com.emc.atmos.api.test.AtmosApiClientTest.java
@Test public void testGetShareableUrlWithPathAndUTF8Disposition() throws Exception { // Create an object with content. Assume.assumeFalse(isVipr);/*from www. j a va 2 s . c o m*/ String str = "Four score and twenty years ago"; ObjectPath op = new ObjectPath("/" + rand8char() + ".txt"); ObjectId id = this.api.createObject(op, str.getBytes("UTF-8"), "text/plain"); Assert.assertNotNull("null ID returned", id); //cleanup.add( op ); // One cryllic, one accented, and one japanese character // RFC5987 String disposition = "attachment; filename=\"no UTF support.txt\"; filename*=UTF-8''" + URLEncoder.encode(".txt", "UTF-8"); Calendar c = Calendar.getInstance(); c.add(Calendar.HOUR, 4); Date expiration = c.getTime(); URL u = this.api.getShareableUrl(op, expiration, disposition); l4j.debug("Sharable URL: " + u); InputStream stream = (InputStream) u.getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(stream)); String content = br.readLine(); l4j.debug("Content: " + content); Assert.assertEquals("URL does not contain proper content", str, content); }