Adds an attachment to the message and marks it as spoiler.

@param stream The stream of the file.
@param fileName The name of the file.
@return The current instance in order to chain call methods.
551216
public MessageBuilder addAttachmentAsSpoiler(InputStream stream, String fileName) {
        delegate.addAttachment(stream, "SPOILER_" + fileName);
        return this;
    }
1114395
public MessageBuilder addAttachment(BufferedImage image, String fileName) {
        delegate.addAttachment(image, fileName);
        return this;
    }
689228
public GitlabHTTPRequestor withAttachment(String key, File file) {
        if (file != null && key != null) {
            attachments.put(key, file);
        }
        return this;
    }
585355
public Attachment attachFile(long objectId, InputStream inputStream, String contentType, long contentLength, String fileName) {
        throw new UnsupportedOperationException("Attachments can only be attached to comments, not discussions.");
    }
278943
public E attachment(byte[] attachment, String name) {
        attachments.put(name, attachment);
        return getThis();
    }
95717
public MultipartBuilder attachment(InputStream is, String filename) {
        return bodyPart(new StreamDataBodyPart(ATTACHMENT_NAME, is, filename));
    }
13333
@Override
    public InputStream getAttachment(final Asset asset, final Attachment attachment) throws IOException, BadVersionException, RequestFailureException {
        final ZipFile repoZip = createZipFile();

        if (null == repoZip) {
            return null;
        }

        InputStream retInputStream = null;
        String attachmentId = attachment.get_id();

        try {
            if (attachmentId.contains("#")) {
                String assetId = asset.get_id();
                // new funky code to get an input stream to the license *inside* the main attachment. The start of
                // the assetId will point to the main attachment file.
                ZipEntry entry = createFromRelative(assetId);

                // If the entry wasn't found return null
                if (null == entry) {
                    return null;
                }

                // Get zip input stream to the asset inside the zip
                ZipInputStream zis = new ZipInputStream(repoZip.getInputStream(entry));

                // Get the input stream to the attachment inside the zip
                retInputStream = getInputStreamToLicenseInsideZip(zis, assetId, attachmentId);

            } else {
                // Get input stream to the attachment
                ZipEntry entry = createFromRelative(attachmentId);
                retInputStream = repoZip.getInputStream(entry);
            }
        } finally {
            // If we are throwing an exception the InputStream is never created so the logic below
            // to close the ZipFile when the InputStream is closed will never be called. So lets close
            // the ZipFile now as there is no InputStream to read from.
            if (retInputStream == null) {
                repoZip.close();
            }
        }

        // When the input stream gets closed we also need to close the ZipFile, however
        // the caller only has the input stream. So lets wrap the input stream and close
        // both the inputStream and the ZipFile when the caller calls close on the wrapped
        // input stream
        final InputStream is = retInputStream;
        InputStream wrappedIs = new InputStream() {

            /** {@inheritDoc} */
            @Override
            public int read(byte[] b) throws IOException {
                return is.read(b);
            }

            /** {@inheritDoc} */
            @Override
            public int read(byte[] b, int off, int len) throws IOException {
                return is.read(b, off, len);
            }

            /** {@inheritDoc} */
            @Override
            public long skip(long n) throws IOException {
                return is.skip(n);
            }

            /** {@inheritDoc} */
            @Override
            public int available() throws IOException {
                return is.available();
            }

            /** {@inheritDoc} */
            @Override
            public synchronized void mark(int readlimit) {
                is.mark(readlimit);
            }

            /** {@inheritDoc} */
            @Override
            public synchronized void reset() throws IOException {
                is.reset();
            }

            /** {@inheritDoc} */
            @Override
            public boolean markSupported() {
                return is.markSupported();
            }

            /** {@inheritDoc} */
            @Override
            public int read() throws IOException {
                return is.read();
            }

            /** {@inheritDoc} */
            @Override
            public void close() throws IOException {
                // When the input stream is closed, also close the zip file
                is.close();
                repoZip.close();
            }
        };
        return wrappedIs;
    }
860091
public static OutputStream getFileOutputStream(String filename) throws IOException {
    OutputStream out = new FileOutputStream(filename);
    if (filename.endsWith(".gz")) {
      out = new GZIPOutputStream(out);
    } else if (filename.endsWith(".bz2")) {
      //out = new CBZip2OutputStream(out);
      out = getBZip2PipedOutputStream(filename);
    }
    return out;
  }
603700
public static AsyncWork<XMLDocument, Exception> create(XMLStreamEventsAsync stream) {
		XMLDocument doc = new XMLDocument();
		AsyncWork<XMLDocument, Exception> result = new AsyncWork<>();
		create(doc, stream, result, new SynchronizationPoint<>(true));
		return result;
	}
816198
public static Attachment fromTextInputStream( InputStream inputStream, MediaType mediaType ) throws IOException {
        return fromText( CharStreams.toString( new InputStreamReader( inputStream, mediaType.getCharset() ) ), mediaType );
    }
451523
private static void addAttachments(Map<String, ? extends Attachment> attachments,
                                   Map<String, Object> outMap,
                                   boolean shouldInline,
                                   int minRevPos) {
        // Use a LinkedHashMap which has "predictable iteration order" - this means that the
        // serializer will output the _attachments entries in the same order as the multipart bodies
        // Note that we have already sorted entries by their key (see below where a TreeMap is used)
        // se we only need *this* map to have an iteration order which is in the insertion order
        LinkedHashMap<String, Object> attsMap = new LinkedHashMap<String, Object>();
        outMap.put("_attachments", attsMap);

        // first sort by attachment name - this means that the
        // entries in the _attachments dictionary are in the same
        // order as the multiparts
        attachments = new TreeMap<String, Attachment>(attachments);
        for (Map.Entry<String, ? extends Attachment> att : attachments.entrySet()) {
            // we need to cast down to SavedAttachment, which we know is what the AttachmentManager gives us
            SavedAttachment savedAtt = (SavedAttachment) att.getValue();
            HashMap<String, Object> theAtt = new HashMap<String, Object>();
            try {
                // add the attachment if it's newer than the minimum revpos
                if (savedAtt.revpos > minRevPos) {
                    if (!shouldInline) {
                        theAtt.put("follows", true);
                    } else {
                        theAtt.put("follows", false);
                        // base64 encode this attachment
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        OutputStream bos = Base64OutputStreamFactory.get(baos);
                        InputStream fis = savedAtt.getInputStream();
                        try {
                            int bufSiz = 1024;
                            byte[] buf = new byte[bufSiz];
                            int n = 0;
                            do {
                                n = fis.read(buf);
                                if (n > 0) {
                                    bos.write(buf, 0, n);
                                }
                            } while (n > 0);
                            // out of paranoia, close and flush - docs don't say what you have to
                            // do to

                            // ensure all base64 is written, but close seems to do the right
                            // thing with
                            // the apache codec implementation
                            bos.flush();
                            bos.close();
                            theAtt.put("data", new String(baos.toByteArray(), "UTF-8")); //base64 of data
                        } finally {
                            IOUtils.closeQuietly(fis);
                        }
                    }
                    theAtt.put("length", savedAtt.length);
                    theAtt.put("encoded_length", savedAtt.encodedLength);
                    theAtt.put("content_type", savedAtt.type);
                    theAtt.put("revpos", savedAtt.revpos);
                    if (savedAtt.encoding != Attachment.Encoding.Plain) {
                        theAtt.put("encoding", savedAtt.encoding.toString().toLowerCase(Locale.ENGLISH));
                    }
                } else {
                    // if the revpos of the attachment is higher than the minimum, it's a stub
                    theAtt.put("stub", true);
                }
            } catch (IOException ioe) {
                // if we can't read the file containing the attachment then skip it
                // (this should only occur if someone tampered with the attachments directory
                // or something went seriously wrong)
                logger.log(Level.WARNING,String.format("Error reading attachment %s",att),ioe);
                continue;
            }
            // now we are done, add the attachment to the map
            attsMap.put(att.getKey(), theAtt);
        }
    }
503520
def make_fileitem_streamlist_stream_name(stream_name, condition='is', negate=False, preserve_case=False):
    
    document = 'FileItem'
    search = 'FileItem/StreamList/Stream/Name'
    content_type = 'string'
    content = stream_name
    ii_node = ioc_api.make_indicatoritem_node(condition, document, search, content_type, content,
                                              negate=negate, preserve_case=preserve_case)
    return ii_node
1333418
function addToStream(stream) {
  // Don't add more than once
  if (stream.listeners('addListener').includes(addListener)) {
    return stream;
  }

  stream.on('newListener', addListener);

  return stream;
}
811749
@Override
  public Streamlet<R> setName(String sName) {
    checkNotBlank(sName, "Streamlet name cannot be null/blank");

    this.name = sName;
    return this;
  }
36522
public static SeekableSource onTempFileSeekableSourceFrom(InputStream stream) throws IOException {
        requireNonNull(stream);
        Path temp = Files.createTempFile("SejdaIO", null);
        Files.copy(stream, temp, StandardCopyOption.REPLACE_EXISTING);
        return new BufferedSeekableSource(new FileChannelSeekableSource(temp.toFile()) {
            @Override
            public void close() throws IOException {
                super.close();
                Files.deleteIfExists(temp);
            }
        });
    }
1121780
def add_attachment(message, attachment, rfc2231=True):
    '''
    '''
    data = attachment.read()

    part = MIMEBase('application', 'octet-stream')
    part.set_payload(data)
    encoders.encode_base64(part)
    filename = attachment.name if rfc2231 else Header(attachment.name).encode()
    part.add_header('Content-Disposition', 'attachment',
                    filename=filename)

    message.attach(part)
133095
public static function fromStream($stream, string $filename = null, string $contentType = null)
    {
        $content = stream_get_contents($stream);

        if (null === $contentType) {
            $finfo = new \finfo(FILEINFO_MIME);
            $contentType = $finfo->buffer($content);
            list($contentType) = explode(';', $contentType);
        }

        if (null === $filename) {
            $filename = basename(stream_get_meta_data($stream)['uri']);
        }

        return new static($content, $filename, $contentType);
    }