001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.compress.harmony.pack200; 018 019import java.beans.PropertyChangeListener; 020import java.beans.PropertyChangeSupport; 021import java.util.SortedMap; 022import java.util.TreeMap; 023 024/** 025 * Provides generic JavaBeans support for the Pack/UnpackAdapters 026 */ 027public abstract class Pack200Adapter { 028 029 protected static final int DEFAULT_BUFFER_SIZE = 8192; 030 031 private final PropertyChangeSupport support = new PropertyChangeSupport(this); 032 033 private final SortedMap<String, String> properties = new TreeMap<>(); 034 035 public SortedMap<String, String> properties() { 036 return properties; 037 } 038 039 public void addPropertyChangeListener(final PropertyChangeListener listener) { 040 support.addPropertyChangeListener(listener); 041 } 042 043 protected void firePropertyChange(final String propertyName, final Object oldValue, final Object newValue) { 044 support.firePropertyChange(propertyName, oldValue, newValue); 045 } 046 047 public void removePropertyChangeListener(final PropertyChangeListener listener) { 048 support.removePropertyChangeListener(listener); 049 } 050 051 /** 052 * Completion between 0..1. 053 * 054 * @param value Completion between 0..1. 055 */ 056 protected void completed(final double value) { 057 firePropertyChange("pack.progress", null, String.valueOf((int) (100 * value))); //$NON-NLS-1$ 058 } 059}