Refine search
flags = source.getFlags(); if (flags == null) // make sure flags is always set flags = new Flags(); ByteArrayOutputStream bos; int size = source.getSize(); bos.close(); SharedByteArrayInputStream bis = new SharedByteArrayInputStream(bos.toByteArray()); parse(bis); bis.close(); saved = true; } catch (IOException ex) {
public InputStream toStream() { return new SharedByteArrayInputStream(buf, 0, count); } }
private SimpleMailboxMessage createMessage(MailboxId mailboxId) { int size = 45; int bodyStartOctet = 25; byte[] content = "Subject: test\r\n\r\nBody\r\n".getBytes(StandardCharsets.UTF_8); return new SimpleMailboxMessage(TestMessageId.of(58), new Date(), size, bodyStartOctet, new SharedByteArrayInputStream(content), new Flags(), new PropertyBuilder(), mailboxId); } }
// Get the message object from the folder in the // usual way, for example: MimeMessage msg = (MimeMessage)folder.getMessage(n); // Copy the message by writing into an byte array and // creating a new MimeMessage object based on the contents // of the byte array: ByteArrayOutputStream bos = new ByteArrayOutputStream(); msg.writeTo(bos); bos.close(); SharedByteArrayInputStream bis = new SharedByteArrayInputStream(bos.toByteArray()); MimeMessage cmsg = new MimeMessage(session, bis); bis.close(); // The cmsg object is disconnected from the server so // setFlags will have no effect (for example). Use // the original msg object for such operations. Use // the cmsg object to access the content of the message.
mimeMessage = new MimeMessage(null, new SharedByteArrayInputStream(mimeContent)); byte[] mimeContentCopy = new byte[((SharedByteArrayInputStream) mimeMessage.getRawInputStream()).available()]; int offset = mimeContent.length - mimeContentCopy.length; mimeMessage = new MimeMessage(null, new SharedByteArrayInputStream(mimeContent));
SharedByteArrayInputStream stream = (SharedByteArrayInputStream) content; ByteArrayOutputStream bOut = new ByteArrayOutputStream(); //Reading in chunks is better performance-wise than reading one byte at once. int r; byte[] buffer = new byte[32 * 1000]; //Read and write into the ByteArrayOutputStream while((r = stream.read(buffer) != -1){ bOut.write(buffer, 0, r); } String aloha = new String(bOut.toByteArray(), Charset.forName( "ISO-8859-1" )); writer.append(aloha+"\n"); stream.close();
@Override public void dispose() { try { in.close(); } catch (IOException e) { //ignore exception during close } LifecycleUtil.dispose(in); try { message.clearBody(); } catch (JMSException e) { LOGGER.error("Error clearing JMS message body", e); } try { message.clearProperties(); } catch (JMSException e) { LOGGER.error("Error clearing JMS message properties", e); } content = null; }
public InputStream toStream() { return new SharedByteArrayInputStream(buf, 0, count); } }
@Test public void convertToJsonShouldThrowWhenNoUser() { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); MailboxMessage spamMail = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream("message".getBytes(StandardCharsets.UTF_8)), new Flags(), propertyBuilder, MAILBOX_ID); ImmutableList<User> users = ImmutableList.of(); assertThatThrownBy(() -> messageToElasticSearchJson.convertToJson(spamMail, users)) .isInstanceOf(IllegalStateException.class); }
bos.close(); SharedByteArrayInputStream bis = new SharedByteArrayInputStream(bos.toByteArray()); parse(bis); bis.close(); saved = true; } catch (IOException ex) {
FileOutputStream fileOutputStream = new FileOutputStream(filepath); SharedByteArrayInputStream stream = (SharedByteArrayInputStream) content; byte bite = 0; byte[] buffer = new byte[1024]; //here we're reading more than one byte at a time. while((bite=(byte) stream.read(buffer))!=-1){ //write to file output stream instead. fileOutputStream.write(buffer,0,bite); //don't append new line character. } stream.close(); //close the output stream if you're done. fileOutputStream.close();
flags = source.getFlags(); if (flags == null) // make sure flags is always set flags = new Flags(); ByteArrayOutputStream bos; int size = source.getSize(); bos.close(); SharedByteArrayInputStream bis = new SharedByteArrayInputStream(bos.toByteArray()); parse(bis); bis.close(); saved = true; } catch (IOException ex) {
/** * Return an InputStream for the data. * Note that a new stream is returned each time * this method is called. * * @return the InputStream * @exception IOException if no data has been set */ public InputStream getInputStream() throws IOException { if (data == null) throw new IOException("no data"); if (len < 0) len = data.length; return new SharedByteArrayInputStream(data, 0, len); }
private SimpleMailboxMessage createMessage(MessageId messageId, String content, int bodyStart, PropertyBuilder propertyBuilder, Collection<MessageAttachment> attachments) { return SimpleMailboxMessage.builder() .messageId(messageId) .mailboxId(MAILBOX_ID) .uid(messageUid) .internalDate(new Date()) .bodyStartOctet(bodyStart) .size(content.length()) .content(new SharedByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))) .flags(new Flags()) .propertyBuilder(propertyBuilder) .addAttachments(attachments) .build(); }
bos.close(); SharedByteArrayInputStream bis = new SharedByteArrayInputStream( bos.toByteArray()); MimeMessage cmsg = new MimeMessage( session, bis ); bis.close();
flags = source.getFlags(); if (flags == null) // make sure flags is always set flags = new Flags(); ByteArrayOutputStream bos; int size = source.getSize(); bos.close(); SharedByteArrayInputStream bis = new SharedByteArrayInputStream(bos.toByteArray()); parse(bis); bis.close(); saved = true; } catch (IOException ex) {
/** * Return an InputStream for the data. * Note that a new stream is returned each time * this method is called. * * @return the InputStream * @exception IOException if no data has been set */ @Override public InputStream getInputStream() throws IOException { if (data == null) throw new IOException("no data"); if (len < 0) len = data.length; return new SharedByteArrayInputStream(data, 0, len); }
private SimpleMailboxMessage createMessage(MessageId messageId, Collection<MessageAttachment> attachments) { MessageUid messageUid = MessageUid.of(1); CassandraId mailboxId = CassandraId.timeBased(); String content = "Subject: Any subject \n\nThis is the body\n.\n"; int bodyStart = 22; return SimpleMailboxMessage.builder() .messageId(messageId) .mailboxId(mailboxId) .uid(messageUid) .internalDate(new Date()) .bodyStartOctet(bodyStart) .size(content.length()) .content(new SharedByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))) .flags(new Flags()) .propertyBuilder(new PropertyBuilder()) .addAttachments(attachments) .build(); }
flags = source.getFlags(); if (flags == null) // make sure flags is always set flags = new Flags(); ByteArrayOutputStream bos; int size = source.getSize(); bos.close(); SharedByteArrayInputStream bis = new SharedByteArrayInputStream(bos.toByteArray()); parse(bis); bis.close(); saved = true; } catch (IOException ex) {
/** * Return a new InputStream representing a subset of the data * from this InputStream, starting at <code>start</code> (inclusive) * up to <code>end</code> (exclusive). <code>start</code> must be * non-negative. If <code>end</code> is -1, the new stream ends * at the same place as this stream. The returned InputStream * will also implement the SharedInputStream interface. * * @param start the starting position * @param end the ending position + 1 * @return the new stream */ public InputStream newStream(long start, long end) { if (start < 0) throw new IllegalArgumentException("start < 0"); if (end == -1) end = count - this.start; return new SharedByteArrayInputStream(buf, this.start + (int)start, (int)(end - start)); } }