List of usage examples for java.io ByteArrayInputStream close
public void close() throws IOException
From source file:module.fileSupport.metadata.parsing.FileMetaDataParser.java
public void parse(GenericFile file, FileMetadata metaData) { byte[] content = file.getContent(); ByteArrayInputStream stream = new ByteArrayInputStream(content); String extractedText = null;//from w w w. j av a 2s .c o m try { extractedText = extract(stream); } finally { try { stream.close(); } catch (Exception e) { e.printStackTrace(); } } if (!StringUtils.isEmpty(extractedText)) { metaData.addMetaData(MetadataParserChain.TEXT_CONTENT_PROPERTY, extractedText); } }
From source file:ch.cyberduck.core.openstack.SwiftLargeUploadWriteFeatureTest.java
@Test public void testWriteZeroLength() throws Exception { final Host host = new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com", new Credentials(System.getProperties().getProperty("rackspace.key"), System.getProperties().getProperty("rackspace.secret"))); final SwiftSession session = new SwiftSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final SwiftRegionService regionService = new SwiftRegionService(session); final SwiftLargeUploadWriteFeature feature = new SwiftLargeUploadWriteFeature(session, regionService, new SwiftSegmentService(session, ".segments-test/")); final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume)); final byte[] content = RandomUtils.nextBytes(0); final TransferStatus status = new TransferStatus(); status.setLength(-1L);// w w w. j av a2 s . c o m final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); final HttpResponseOutputStream<List<StorageObject>> out = feature.write(file, status, new DisabledConnectionCallback()); final ByteArrayInputStream in = new ByteArrayInputStream(content); assertEquals(content.length, IOUtils.copyLarge(in, out)); in.close(); out.close(); assertNotNull(out.getStatus()); assertTrue(new DefaultFindFeature(session).find(file)); final byte[] compare = new byte[content.length]; final InputStream stream = new SwiftReadFeature(session, regionService).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback()); IOUtils.readFully(stream, compare); stream.close(); assertArrayEquals(content, compare); new SwiftDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
From source file:de.nieblings.webapp.core.LicenceServiceImpl.java
private Properties loadProps(final byte[] bytes) throws IOException { final Properties properties = new Properties(); final ByteArrayInputStream in = new ByteArrayInputStream(bytes); try {/*www . j a va 2 s. c o m*/ properties.load(in); } finally { in.close(); } return properties; }
From source file:org.jboss.bqt.core.util.FileUtils.java
/** * Write a byte array to a file./*from www. jav a 2s . c om*/ * @param data * @param file * @throws IOException */ public static void write(byte[] data, File file) throws IOException { ByteArrayInputStream bais = null; InputStream is = null; try { bais = new ByteArrayInputStream(data); is = new BufferedInputStream(bais); write(is, file); } finally { if (is != null) { is.close(); } if (bais != null) { bais.close(); } } }
From source file:com.enonic.cms.core.portal.instruction.PostProcessInstruction.java
public final void deserialize(String value) throws IOException, ClassNotFoundException { ByteArrayInputStream in = new ByteArrayInputStream(Base64.decodeBase64(value.getBytes())); ObjectInputStream din = new ObjectInputStream(in); readExternal(din);/*from w ww .ja v a 2 s . com*/ in.close(); din.close(); }
From source file:com.company.project.web.controller.WebSocketController.java
@MessageMapping("/imageFileShareMapping") @SendTo("/topic/imageFileShareResponse") public String imageFileShare(String param) throws Exception { BufferedImage image = null;/*ww w . j ava2 s. c o m*/ byte[] imageByte; try { BASE64Decoder decoder = new BASE64Decoder(); imageByte = decoder.decodeBuffer(param.split(",")[1]); ByteArrayInputStream bis = new ByteArrayInputStream(imageByte); image = ImageIO.read(bis); bis.close(); } catch (Exception e) { e.printStackTrace(); } File outputfile = new File("D:/GemShelf/" + UUID.randomUUID() + ".jpg"); ImageIO.write(image, "jpg", outputfile); return param; }
From source file:org.jboss.bqt.core.util.FileUtils.java
/** * Write a byte array to a file.//from w ww .j a va 2 s. co m * @param data * @param fileName * @throws IOException */ public static void write(byte[] data, String fileName) throws IOException { ByteArrayInputStream bais = null; InputStream is = null; try { bais = new ByteArrayInputStream(data); is = new BufferedInputStream(bais); write(is, fileName); } finally { if (is != null) { is.close(); } if (bais != null) { bais.close(); } } }
From source file:ch.cyberduck.core.b2.B2LargeUploadWriteFeatureTest.java
@Test public void testWriteLowerMinimumSize() throws Exception { final B2Session session = new B2Session(new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(), new Credentials(System.getProperties().getProperty("b2.user"), System.getProperties().getProperty("b2.key")))); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final B2LargeUploadWriteFeature feature = new B2LargeUploadWriteFeature(session); final Path container = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final TransferStatus status = new TransferStatus(); status.setLength(-1L);/*from ww w .ja va 2s.c om*/ final Path file = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final OutputStream out = feature.write(file, status, new DisabledConnectionCallback()); final byte[] content = new RandomStringGenerator.Builder().build().generate(2 * 1024 * 1024) .getBytes("UTF-8"); final ByteArrayInputStream in = new ByteArrayInputStream(content); assertEquals(content.length, IOUtils.copy(in, out)); in.close(); out.close(); assertTrue(new B2FindFeature(session).find(file)); final byte[] compare = new byte[content.length]; final InputStream stream = new B2ReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback()); IOUtils.readFully(stream, compare); stream.close(); assertArrayEquals(content, compare); new B2DeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.b2.B2LargeUploadWriteFeatureTest.java
@Test public void testWrite() throws Exception { final B2Session session = new B2Session(new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(), new Credentials(System.getProperties().getProperty("b2.user"), System.getProperties().getProperty("b2.key")))); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final B2LargeUploadWriteFeature feature = new B2LargeUploadWriteFeature(session); final Path container = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final TransferStatus status = new TransferStatus(); status.setLength(-1L);/* w ww. j av a 2s. c om*/ status.setTimestamp(1503654614004L); final Path file = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final OutputStream out = feature.write(file, status, new DisabledConnectionCallback()); final byte[] content = new RandomStringGenerator.Builder().build().generate(6 * 1024 * 1024) .getBytes("UTF-8"); final ByteArrayInputStream in = new ByteArrayInputStream(content); assertEquals(content.length, IOUtils.copy(in, out)); in.close(); out.close(); assertTrue(new B2FindFeature(session).find(file)); final byte[] compare = new byte[content.length]; final InputStream stream = new B2ReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback()); IOUtils.readFully(stream, compare); stream.close(); assertArrayEquals(content, compare); assertEquals(1503654614004L, new B2AttributesFinderFeature(session).find(file).getModificationDate()); new B2DeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:io.cortical.retina.core.ImagesTest.java
/** * {@link Images#compareImage(List, Integer, ImagePlotShape, ImageEncoding)} * //from w w w .ja v a 2s . c o m * @throws ApiException : should never be thrown. * @throws IOException */ @Test public void compareModelTest() throws ApiException, IOException { ImagePlotShape shape = ImagePlotShape.CIRCLE; ImageEncoding encoding = ImageEncoding.BASE64_PNG; List<Term> terms = Arrays.asList(TERM_1, TERM_2); when(api.getOverlayImage(eq(TERM_1_TERM_2_JSON), eq(NOT_NULL_RETINA), eq(shape.name().toLowerCase()), eq(1), eq(encoding.machineRepresentation()))) .thenReturn(new ByteArrayInputStream(new byte[] { "i".getBytes()[0] })); ByteArrayInputStream stream = images.compareImage(terms, 1, shape, encoding); assertNotNull(stream); assertEquals(105, stream.read()); stream.close(); verify(api, times(1)).getOverlayImage(eq(TERM_1_TERM_2_JSON), eq(NOT_NULL_RETINA), eq(shape.name().toLowerCase()), eq(1), eq(encoding.machineRepresentation())); }