javax.mail.util.SharedByteArrayInputStream类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(2329)

本文整理了Java中javax.mail.util.SharedByteArrayInputStream类的一些代码示例,展示了SharedByteArrayInputStream类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SharedByteArrayInputStream类的具体详情如下:
包路径:javax.mail.util.SharedByteArrayInputStream
类名称:SharedByteArrayInputStream

SharedByteArrayInputStream介绍

[英]A ByteArrayInputStream that implements the SharedInputStream interface, allowing the underlying byte array to be shared between multiple readers.
[中]实现SharedInputStream接口的ByteArrayInputStream,允许在多个读卡器之间共享底层字节数组。

代码示例

代码示例来源:origin: camunda/camunda-bpm-platform

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) {

代码示例来源:origin: camunda/camunda-bpm-platform

public InputStream toStream() {
  return new SharedByteArrayInputStream(buf, 0, count);
  }
}

代码示例来源:origin: org.apache.james/apache-james-mailbox-spamassassin

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);
  }
}

代码示例来源:origin: stackoverflow.com

// 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.

代码示例来源:origin: mguessan/davmail

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));

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: org.apache.james/james-server-queue-jms

@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;
}

代码示例来源:origin: com.sun.mail/javax.mail

public InputStream toStream() {
  return new SharedByteArrayInputStream(buf, 0, count);
  }
}

代码示例来源:origin: org.apache.james/apache-james-mailbox-elasticsearch

@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);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.javax.mail

bos.close();
  SharedByteArrayInputStream bis =
      new SharedByteArrayInputStream(bos.toByteArray());
  parse(bis);
  bis.close();
  saved = true;
} catch (IOException ex) {

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: com.sun.mail/javax.mail

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) {

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * 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);
}

代码示例来源:origin: org.apache.james/apache-james-mailbox-cassandra

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();
}

代码示例来源:origin: org.ow2.petals/petals-bc-mail

bos.close();
SharedByteArrayInputStream bis = new SharedByteArrayInputStream( bos.toByteArray());
MimeMessage cmsg = new MimeMessage( session, bis );
bis.close();

代码示例来源:origin: javax.mail/com.springsource.javax.mail

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) {

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * 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);
}

代码示例来源:origin: org.apache.james/apache-james-mailbox-cassandra

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();
}

代码示例来源:origin: com.sun.mail/jakarta.mail

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) {

代码示例来源:origin: camunda/camunda-bpm-platform

/**
   * 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));
  }
}

相关文章