Code example for ImmutableMultimap.Builder

Methods: build, put

0
       
      @Override 
      public Multimap<String, String> toHeaders(ContentMetadata md) {
         Builder<String, String> builder = ImmutableMultimap.builder();
         if (md.getContentType() != null)
            builder.put(CONTENT_TYPE, md.getContentType());
         if (md.getContentDisposition() != null)
            builder.put(CONTENT_DISPOSITION, md.getContentDisposition());
         if (md.getContentEncoding() != null)
            builder.put(CONTENT_ENCODING, md.getContentEncoding());
         if (md.getContentLanguage() != null)
            builder.put(CONTENT_LANGUAGE, md.getContentLanguage());
         if (md.getContentLength() != null)
            builder.put(CONTENT_LENGTH, md.getContentLength() + "");
         if (md.getContentMD5() != null)
            builder.put(CONTENT_MD5, base64().encode(md.getContentMD5()));
         if (md.getExpires() != null)
            builder.put(EXPIRES, getExpiresDateCodec().toString(md.getExpires()));
         return builder.build();
      } 
       
      @Override 
      public void fromHeaders(MutableContentMetadata contentMetadata, Multimap<String, String> headers) {
         boolean chunked = any(headers.entries(), new Predicate<Entry<String, String>>() {
            @Override 
            public boolean apply(Entry<String, String> input) {
               return "Transfer-Encoding".equalsIgnoreCase(input.getKey()) && "chunked".equalsIgnoreCase(input.getValue());
            } 
         }); 
         for (Entry<String, String> header : headers.entries()) {
            if (!chunked && CONTENT_LENGTH.equalsIgnoreCase(header.getKey())) {
               contentMetadata.setContentLength(Long.valueOf(header.getValue()));
            } else if (CONTENT_MD5.equalsIgnoreCase(header.getKey())) {
               contentMetadata.setContentMD5(base64().decode(header.getValue()));
            } else if (CONTENT_TYPE.equalsIgnoreCase(header.getKey())) {
               contentMetadata.setContentType(header.getValue());
            } else if (CONTENT_DISPOSITION.equalsIgnoreCase(header.getKey())) {
               contentMetadata.setContentDisposition(header.getValue());
            } else if (CONTENT_ENCODING.equalsIgnoreCase(header.getKey())) {
               contentMetadata.setContentEncoding(header.getValue());
            } else if (CONTENT_LANGUAGE.equalsIgnoreCase(header.getKey())) {
               contentMetadata.setContentLanguage(header.getValue());
            } else if (EXPIRES.equalsIgnoreCase(header.getKey())) {
               contentMetadata.setExpires(parseExpires(header.getValue()));
            } 
         } 
      } 
       
      public Date parseExpires(String expires) {
         try { 
            return (expires != null) ? getExpiresDateCodec().toDate(expires) : null;
         } catch (IllegalArgumentException e) {
            logger.debug("Invalid Expires header (%s); should be in RFC-1123 format; treating as already expired: %s", 
                  expires, e.getMessage());
            return new Date(0);
Experience pair programming with AI  Get Codota for Java