List of usage examples for org.apache.commons.io Charsets UTF_8
Charset UTF_8
To view the source code for org.apache.commons.io Charsets UTF_8.
Click Source Link
Eight-bit Unicode Transformation Format.
From source file:org.dspace.app.util.GoogleMetadataTest.java
/** * When multiple bitstreams with the sametype are found, it returns the largest one * @throws Exception/*from ww w. j a v a2s . c o m*/ */ @Test public void testGetPDFURLSameMimeTypes() throws Exception { context.turnOffAuthorisationSystem(); Bundle bundle = ContentServiceFactory.getInstance().getBundleService().create(context, it, "ORIGINAL"); ; Bitstream b = bitstreamService.create(context, new ByteArrayInputStream("123456789".getBytes(Charsets.UTF_8))); b.setName(context, "size9"); b.setFormat(context, bitstreamFormatService.create(context)); b.getFormat(context).setMIMEType("application/pdf"); bundleService.addBitstream(context, bundle, b); Bitstream b2 = bitstreamService.create(context, new ByteArrayInputStream("1".getBytes(Charsets.UTF_8))); b2.setName(context, "size1"); b2.setFormat(context, bitstreamFormatService.create(context)); b2.getFormat(context).setMIMEType("application/pdf"); bundleService.addBitstream(context, bundle, b2); Bitstream b3 = bitstreamService.create(context, new ByteArrayInputStream("12345".getBytes(Charsets.UTF_8))); b3.setName(context, "size5"); b3.setFormat(context, bitstreamFormatService.create(context)); b3.getFormat(context).setMIMEType("text/richtext"); bundleService.addBitstream(context, bundle, b3); context.restoreAuthSystemState(); context.commit(); GoogleMetadata gm = new GoogleMetadata(this.context, it); String[] urlSplitted = gm.getPDFURL().get(0).split("/"); assertEquals("size9", urlSplitted[urlSplitted.length - 1]); }
From source file:org.dspace.app.util.GoogleMetadataTest.java
/** * Multiple bitstreams with same mimetype and size, just returns the first one * @throws Exception/*from www . j a v a 2s . c o m*/ */ @Test public void testGetPDFURLSameMimeTypesSameSize() throws Exception { context.turnOffAuthorisationSystem(); Bundle bundle = ContentServiceFactory.getInstance().getBundleService().create(context, it, "ORIGINAL"); ; Bitstream b = bitstreamService.create(context, new ByteArrayInputStream("1".getBytes(Charsets.UTF_8))); b.setName(context, "first"); b.setFormat(context, bitstreamFormatService.create(context)); b.getFormat(context).setMIMEType("application/pdf"); bundleService.addBitstream(context, bundle, b); Bitstream b2 = bitstreamService.create(context, new ByteArrayInputStream("1".getBytes(Charsets.UTF_8))); b2.setName(context, "second"); b2.setFormat(context, bitstreamFormatService.create(context)); b2.getFormat(context).setMIMEType("application/pdf"); bundleService.addBitstream(context, bundle, b2); Bitstream b3 = bitstreamService.create(context, new ByteArrayInputStream("1".getBytes(Charsets.UTF_8))); b3.setName(context, "third"); b3.setFormat(context, bitstreamFormatService.create(context)); b3.getFormat(context).setMIMEType("application/pdf"); bundleService.addBitstream(context, bundle, b3); context.restoreAuthSystemState(); context.commit(); GoogleMetadata gm = new GoogleMetadata(this.context, it); String[] urlSplitted = gm.getPDFURL().get(0).split("/"); assertEquals("first", urlSplitted[urlSplitted.length - 1]); }
From source file:org.dspace.app.util.GoogleMetadataTest.java
/** * Test to see if that when an item is marked as primary, that it will still be the result of getPdfURL() * @throws Exception/* www. j a v a 2 s. c o m*/ */ @Test public void testGetPDFURLWithPrimaryBitstream() throws Exception { context.turnOffAuthorisationSystem(); Bundle bundle = ContentServiceFactory.getInstance().getBundleService().create(context, it, "ORIGINAL"); ; Bitstream b = bitstreamService.create(context, new ByteArrayInputStream("Larger file than primary".getBytes(Charsets.UTF_8))); b.setName(context, "first"); b.setFormat(context, bitstreamFormatService.create(context)); b.getFormat(context).setMIMEType("unknown"); bundleService.addBitstream(context, bundle, b); Bitstream b2 = bitstreamService.create(context, new ByteArrayInputStream( "Bitstream with more prioritized mimetype than primary".getBytes(Charsets.UTF_8))); b2.setName(context, "second"); b2.setFormat(context, bitstreamFormatService.create(context)); b2.getFormat(context).setMIMEType("application/pdf"); bundleService.addBitstream(context, bundle, b2); Bitstream b3 = bitstreamService.create(context, new ByteArrayInputStream("1".getBytes(Charsets.UTF_8))); b3.setName(context, "primary"); b3.setFormat(context, bitstreamFormatService.create(context)); b3.getFormat(context).setMIMEType("Primary"); bundleService.addBitstream(context, bundle, b3); bundle.setPrimaryBitstreamID(b3); context.restoreAuthSystemState(); context.commit(); GoogleMetadata gm = new GoogleMetadata(this.context, it); String[] urlSplitted = gm.getPDFURL().get(0).split("/"); assertEquals("primary", urlSplitted[urlSplitted.length - 1]); }
From source file:org.dspace.app.util.GoogleMetadataTest.java
/** * Test to make sure mimetypes can be undefined in the property file, just give them lowest priority if * this is the case and return the largest. * @throws Exception//from w ww. ja va2 s .com */ @Test public void testGetPDFURLWithUndefinedMimeTypes() throws Exception { context.turnOffAuthorisationSystem(); Bundle bundle = ContentServiceFactory.getInstance().getBundleService().create(context, it, "ORIGINAL"); ; Bitstream b = bitstreamService.create(context, new ByteArrayInputStream("12".getBytes(Charsets.UTF_8))); b.setName(context, "small"); b.setFormat(context, bitstreamFormatService.create(context)); b.getFormat(context).setMIMEType("unknown type 1"); bundleService.addBitstream(context, bundle, b); Bitstream b2 = bitstreamService.create(context, new ByteArrayInputStream("12121212".getBytes(Charsets.UTF_8))); b2.setName(context, "medium"); b2.setFormat(context, bitstreamFormatService.create(context)); b2.getFormat(context).setMIMEType("unknown type 2"); bundleService.addBitstream(context, bundle, b2); Bitstream b3 = bitstreamService.create(context, new ByteArrayInputStream("12121212121212".getBytes(Charsets.UTF_8))); b3.setName(context, "large"); b3.setFormat(context, bitstreamFormatService.create(context)); b3.getFormat(context).setMIMEType("unknown type 3"); bundleService.addBitstream(context, bundle, b3); context.restoreAuthSystemState(); context.commit(); GoogleMetadata gm = new GoogleMetadata(this.context, it); String[] urlSplitted = gm.getPDFURL().get(0).split("/"); assertEquals("large", urlSplitted[urlSplitted.length - 1]); }
From source file:org.dspace.app.util.GoogleMetadataTest.java
/** * Test empty bitstreams// w ww .j a v a 2 s.c o m */ @Test public void testGetPDFURLWithEmptyBitstreams() throws Exception { context.turnOffAuthorisationSystem(); Bundle bundle = ContentServiceFactory.getInstance().getBundleService().create(context, it, "ORIGINAL"); ; Bitstream b = bitstreamService.create(context, new ByteArrayInputStream("".getBytes(Charsets.UTF_8))); b.setName(context, "small"); b.setFormat(context, bitstreamFormatService.create(context)); b.getFormat(context).setMIMEType("unknown type 1"); bundleService.addBitstream(context, bundle, b); Bitstream b2 = bitstreamService.create(context, new ByteArrayInputStream("".getBytes(Charsets.UTF_8))); b2.setName(context, "medium"); b2.setFormat(context, bitstreamFormatService.create(context)); b2.getFormat(context).setMIMEType("unknown type 2"); bundleService.addBitstream(context, bundle, b2); Bitstream b3 = bitstreamService.create(context, new ByteArrayInputStream("".getBytes(Charsets.UTF_8))); b3.setName(context, "large"); b3.setFormat(context, bitstreamFormatService.create(context)); b3.getFormat(context).setMIMEType("unknown type 3"); bundleService.addBitstream(context, bundle, b3); context.restoreAuthSystemState(); context.commit(); GoogleMetadata gm = new GoogleMetadata(this.context, it); String[] urlSplitted = gm.getPDFURL().get(0).split("/"); assertEquals("small", urlSplitted[urlSplitted.length - 1]); }
From source file:org.dspace.discovery.FullTextContentStreamsTest.java
@Before public void setUp() throws Exception { when(item.getHandle()).thenReturn(HANDLE); when(originalBundle.getName()).thenReturn("ORIGINAL"); when(textBundle.getName()).thenReturn("TEXT"); when(textBitstream1.getName()).thenReturn("Full Text 1"); when(textBitstream2.getName()).thenReturn("Full Text 2"); when(textBitstream3.getName()).thenReturn("Full Text 3"); when(textBitstream1.getSize()).thenReturn(1L); when(textBitstream2.getSize()).thenReturn(2L); when(textBitstream3.getSize()).thenReturn(3L); when(bitstreamService.retrieve(null, textBitstream1)) .thenReturn(new ByteArrayInputStream("This is text 1".getBytes(Charsets.UTF_8))); when(bitstreamService.retrieve(null, textBitstream2)) .thenReturn(new ByteArrayInputStream("This is text 2".getBytes(Charsets.UTF_8))); when(bitstreamService.retrieve(null, textBitstream3)) .thenReturn(new ByteArrayInputStream("This is text 3".getBytes(Charsets.UTF_8))); streams.bitstreamService = bitstreamService; }
From source file:org.dspace.discovery.FullTextContentStreamsTest.java
@Test public void testItemWithOnlyOneTextBitstream() throws Exception { when(item.getBundles()).thenReturn(Arrays.asList(originalBundle, textBundle)); when(textBundle.getBitstreams()).thenReturn(Arrays.asList(textBitstream1)); streams.init(item);//from www .j a v a 2s. com assertEquals("Source info should give you the handle", HANDLE, streams.getSourceInfo()); assertEquals("Content type should be plain text", CONTENT_TYPE, streams.getContentType()); assertEquals("The name should match the name of the bitstream", "Full Text 1", streams.getName()); assertEquals("The size of the streams should match the size of bitstream 1", (Long) 1L, streams.getSize()); assertFalse("Content stream should not be empty", streams.isEmpty()); InputStream inputStream = streams.getStream(); assertNotNull(inputStream); assertEquals("The data in the input stream should match the text of the bitstream", "\nThis is text 1", IOUtils.toString(inputStream, Charsets.UTF_8)); }
From source file:org.dspace.discovery.FullTextContentStreamsTest.java
@Test public void testItemWithMultipleTextBitstreams() throws Exception { when(item.getBundles()).thenReturn(Arrays.asList(originalBundle, textBundle)); when(textBundle.getBitstreams()).thenReturn(Arrays.asList(textBitstream1, textBitstream2, textBitstream3)); streams.init(item);//from ww w .j a v a2 s . c o m assertEquals("Source info should give you the handle", HANDLE, streams.getSourceInfo()); assertEquals("Content type should be plain text", CONTENT_TYPE, streams.getContentType()); assertEquals("The name should match the concatenation of the names of the bitstreams", "Full Text 1;Full Text 2;Full Text 3", streams.getName()); assertEquals("The size of the streams should be the sum of the bitstream sizes", (Long) 6L, streams.getSize()); assertFalse("Content stream should not be empty", streams.isEmpty()); InputStream inputStream = streams.getStream(); assertNotNull(inputStream); assertEquals("The data in the input stream should match 'This is text 1'", "\nThis is text 1" + "\nThis is text 2\nThis is text 3", IOUtils.toString(inputStream, Charsets.UTF_8)); }
From source file:org.dspace.discovery.FullTextContentStreamsTest.java
@Test public void testBitstreamThrowingExceptionShouldNotStopIndexing() throws Exception { when(item.getBundles()).thenReturn(Arrays.asList(originalBundle, textBundle)); when(textBundle.getBitstreams()).thenReturn(Arrays.asList(textBitstream1, textBitstream2, textBitstream3)); when(bitstreamService.retrieve(null, textBitstream2)).thenThrow(new IOException("NOTFOUND")); streams.init(item);/*w ww.j a va 2 s . c om*/ assertEquals("Source info should give you the handle", HANDLE, streams.getSourceInfo()); assertEquals("Content type should be plain text", CONTENT_TYPE, streams.getContentType()); assertEquals("The name should match the concatenation of the names of the bitstreams", "Full Text 1;Full Text 2;Full Text 3", streams.getName()); assertEquals("The size of the streams should be the sum of the bitstream sizes", (Long) 6L, streams.getSize()); assertFalse("Content stream should not be empty", streams.isEmpty()); InputStream inputStream = streams.getStream(); assertNotNull(inputStream); String content = IOUtils.toString(inputStream, Charsets.UTF_8); assertTrue("The data should contain data of the first bitstream that is not corrupt", content.contains("This is text 1")); assertFalse("The data should NOT contain data of the second bitstream that is corrupt", content.contains("This is text 2")); assertTrue("The data should contain data of the third bistream that is not corrupt", content.contains("This is text 3")); assertTrue("The data should contain data on the exception that occurred", content.contains("java.io.IOException")); assertTrue("The data should contain data on the exception that occurred", content.contains("NOTFOUND")); }
From source file:org.dspace.sword2.SwordUrlManager.java
/** * Central location for constructing usable URLs for DSpace bitstreams. * There is no place in the main DSpace code base for doing this. * * @param bitstream//from www . j av a 2 s. com * @throws DSpaceSwordException */ public String getBitstreamUrl(Bitstream bitstream) throws DSpaceSwordException { try { Bundle[] bundles = bitstream.getBundles(); Bundle parent = null; if (bundles.length > 0) { parent = bundles[0]; } else { throw new DSpaceSwordException("Encountered orphaned bitstream"); } Item[] items = parent.getItems(); Item item; if (items.length > 0) { item = items[0]; } else { throw new DSpaceSwordException("Encountered orphaned bundle"); } String handle = item.getHandle(); String bsLink = ConfigurationManager.getProperty("dspace.url"); if (handle != null && !"".equals(handle)) { bsLink = bsLink + "/bitstream/" + handle + "/" + bitstream.getSequenceID() + "/" + URLEncoder.encode(bitstream.getName(), Charsets.UTF_8.name()); } else { bsLink = bsLink + "/retrieve/" + bitstream.getID() + "/" + URLEncoder.encode(bitstream.getName(), Charsets.UTF_8.name()); } return bsLink; } catch (SQLException e) { throw new DSpaceSwordException(e); } catch (UnsupportedEncodingException e) { throw new DSpaceSwordException("Unable to encode URL", e); } }