Java Code Examples for org.whispersystems.signalservice.internal.util.Util#copy()

The following examples show how to use org.whispersystems.signalservice.internal.util.Util#copy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignalServiceMessageReceiver.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Retrieves a {@link SignalServiceStickerManifest}.
 *
 * @param packId The 16-byte packId that identifies the sticker pack.
 * @param packKey The 32-byte packKey that decrypts the sticker pack.
 * @return The {@link SignalServiceStickerManifest} representing the sticker pack.
 * @throws IOException
 * @throws InvalidMessageException
 */
public SignalServiceStickerManifest retrieveStickerManifest(byte[] packId, byte[] packKey)
    throws IOException, InvalidMessageException
{
  byte[] manifestBytes = socket.retrieveStickerManifest(packId);

  InputStream           cipherStream = AttachmentCipherInputStream.createForStickerData(manifestBytes, packKey);
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

  Util.copy(cipherStream, outputStream);

  StickerProtos.Pack                             pack     = StickerProtos.Pack.parseFrom(outputStream.toByteArray());
  List<SignalServiceStickerManifest.StickerInfo> stickers = new ArrayList<>(pack.getStickersCount());
  SignalServiceStickerManifest.StickerInfo       cover    = pack.hasCover() ? new SignalServiceStickerManifest.StickerInfo(pack.getCover().getId(), pack.getCover().getEmoji())
                                                                        : null;

  for (StickerProtos.Pack.Sticker sticker : pack.getStickersList()) {
    stickers.add(new SignalServiceStickerManifest.StickerInfo(sticker.getId(), sticker.getEmoji()));
  }

  return new SignalServiceStickerManifest(pack.getTitle(), pack.getAuthor(), cover, stickers);
}
 
Example 2
Source File: SignalServiceMessageReceiver.java    From libsignal-service-java with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Retrieves a {@link SignalServiceStickerManifest}.
 *
 * @param packId The 16-byte packId that identifies the sticker pack.
 * @param packKey The 32-byte packKey that decrypts the sticker pack.
 * @return The {@link SignalServiceStickerManifest} representing the sticker pack.
 * @throws IOException
 * @throws InvalidMessageException
 */
public SignalServiceStickerManifest retrieveStickerManifest(byte[] packId, byte[] packKey)
    throws IOException, InvalidMessageException
{
  byte[] manifestBytes = socket.retrieveStickerManifest(packId);

  InputStream           cipherStream = AttachmentCipherInputStream.createForStickerData(manifestBytes, packKey);
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

  Util.copy(cipherStream, outputStream);

  StickerProtos.Pack                             pack     = StickerProtos.Pack.parseFrom(outputStream.toByteArray());
  List<SignalServiceStickerManifest.StickerInfo> stickers = new ArrayList<>(pack.getStickersCount());
  SignalServiceStickerManifest.StickerInfo       cover    = pack.hasCover() ? new SignalServiceStickerManifest.StickerInfo(pack.getCover().getId(), pack.getCover().getEmoji())
                                                                        : null;

  for (StickerProtos.Pack.Sticker sticker : pack.getStickersList()) {
    stickers.add(new SignalServiceStickerManifest.StickerInfo(sticker.getId(), sticker.getEmoji()));
  }

  return new SignalServiceStickerManifest(pack.getTitle(), pack.getAuthor(), cover, stickers);
}
 
Example 3
Source File: AttachmentCipherTest.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private static byte[] readInputStreamFully(InputStream inputStream) throws IOException {
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  Util.copy(inputStream, outputStream);
  return outputStream.toByteArray();
}
 
Example 4
Source File: AttachmentCipherTest.java    From libsignal-service-java with GNU General Public License v3.0 4 votes vote down vote up
private static byte[] readInputStreamFully(InputStream inputStream) throws IOException {
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  Util.copy(inputStream, outputStream);
  return outputStream.toByteArray();
}
 
Example 5
Source File: IOUtils.java    From signal-cli with GNU General Public License v3.0 4 votes vote down vote up
public static byte[] readFully(InputStream in) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Util.copy(in, baos);
    return baos.toByteArray();
}