Java Jar Usage allocateReadOnlyDictionary(final Attributes attributes)

Here you can find the source of allocateReadOnlyDictionary(final Attributes attributes)

Description

allocate Read Only Dictionary

License

Apache License

Declaration

public static Dictionary allocateReadOnlyDictionary(final Attributes attributes) 

Method Source Code

//package com.java2s;
/**//from   ww  w . ja va  2 s. c  o m
 *
 * Copyright 2008-2009 (C) The original author or authors
 *
 * Licensed 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.
 */

import java.util.Collections;
import java.util.Dictionary;
import java.util.Enumeration;

import java.util.HashSet;

import java.util.Set;
import java.util.jar.Attributes;

public class Main {
    public static Dictionary allocateReadOnlyDictionary(final Attributes attributes) {
        return new Dictionary() {
            public int size() {
                return attributes.size();
            }

            public boolean isEmpty() {
                return attributes.isEmpty();
            }

            public Enumeration keys() {
                Set<String> set = new HashSet<String>();
                for (Object key : attributes.keySet())
                    set.add(key.toString());
                return Collections.enumeration(set);
            }

            public Enumeration elements() {
                return Collections.enumeration(attributes.values());
            }

            public Object get(Object key) {
                return attributes.getValue((String) key);
            }

            public Object put(Object key, Object value) {
                throw new UnsupportedOperationException("Read-only dictionary");
            }

            public Object remove(Object key) {
                throw new UnsupportedOperationException("Read-only dictionary");
            }
        };
    }
}

Related

  1. _getPacker()
  2. allocateReadOnlyI18nDictionary(final Attributes attributes, final ResourceBundle resourceBundle)
  3. checkJarValidity(String path)
  4. containsClass(JarFile jarFile, String agentRunnerClassName)
  5. containsClass(JarFile jarFile, String classFilePath)