Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.jclouds.openstack.swift.v1.binders;
 
 import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_METADATA_PREFIX;
 import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_METADATA_PREFIX;
 import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_METADATA_PREFIX;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 
 import java.util.Map;
 
 
Will lower-case header keys due to a swift implementation to return headers in a different case than sent. ex.
 >> X-Account-Meta-MyDelete1: foo
 >> X-Account-Meta-MyDelete2: bar
 
results in:
 << X-Account-Meta-Mydelete1: foo
 << X-Account-Meta-Mydelete2: bar
 

Note


HTTP response headers keys are known to be case-insensitive, but this practice of mixing up case will prevent metadata keys such as those in Turkish from working.
 
 public class BindMetadataToHeaders implements Binder {
 
    public static class BindAccountMetadataToHeaders extends BindMetadataToHeaders {
          super();
       }
    }
 
    public static class BindRemoveAccountMetadataToHeaders extends BindMetadataToHeaders.ForRemoval {
          super();
       }
    }
 
    public static class BindContainerMetadataToHeaders extends BindMetadataToHeaders {
          super();
       }
    }
 
    public static class BindRemoveContainerMetadataToHeaders extends BindMetadataToHeaders.ForRemoval {
          super();
       }
    }
 
    public static class BindObjectMetadataToHeaders extends BindMetadataToHeaders {
          super();
       }
    }
 
    public static class BindRemoveObjectMetadataToHeaders extends BindMetadataToHeaders.ForRemoval {
          super();
       }
    }

   

See also:
documentation
 
    public abstract static class ForRemoval extends BindMetadataToHeaders {
       ForRemoval(String metadataPrefix) {
         super(metadataPrefix);
      }
      @Override
      protected void putMetadata(Builder<StringStringheadersString keyString value) {
         headers.put(String.format("x-remove%s"key.substring(1)), "ignored");
      }
   }
   private final String metadataPrefix;
   public BindMetadataToHeaders(String metadataPrefix) {
      this. = checkNotNull(metadataPrefix"metadataPrefix");
   }
   @SuppressWarnings("unchecked")
   public <R extends HttpRequest> R bindToRequest(R requestObject input) {
      checkNotNull(request"request");
      checkArgument(input instanceof Map<?, ?>, "input must be a non-null java.util.Map!");
      Map<StringStringmetadata = Map.class.cast(input);
      ImmutableMultimap<StringStringheaders = toHeaders(metadata);
      return (R) request.toBuilder().replaceHeaders(headers).build();
   }
   protected void putMetadata(Builder<StringStringheadersString keyString value) {
      headers.put(keyvalue);
   }
   public ImmutableMultimap<StringStringtoHeaders(Map<StringStringmetadata) {
      Builder<StringStringbuilder = ImmutableMultimap.<StringStringbuilder();
      for (Entry<StringStringkeyVal : metadata.entrySet()) {
         String keyInLowercase = keyVal.getKey().toLowerCase();
         if (keyVal.getKey().startsWith()) {
            putMetadata(builderkeyInLowercasekeyVal.getValue());
         } else {
            putMetadata(builder, String.format("%s%s"keyInLowercase), keyVal.getValue());
         }
      }
      return builder.build();
   }
New to GrepCode? Check out our FAQ X