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 void addPropertyChangeListener(final PropertyChangeListener listener) { 036 support.addPropertyChangeListener(listener); 037 } 038 039 /** 040 * Completion between 0..1. 041 * 042 * @param value Completion between 0..1. 043 */ 044 protected void completed(final double value) { 045 firePropertyChange("pack.progress", null, String.valueOf((int) (100 * value))); //$NON-NLS-1$ 046 } 047 048 protected void firePropertyChange(final String propertyName, final Object oldValue, final Object newValue) { 049 support.firePropertyChange(propertyName, oldValue, newValue); 050 } 051 052 public SortedMap<String, String> properties() { 053 return properties; 054 } 055 056 public void removePropertyChangeListener(final PropertyChangeListener listener) { 057 support.removePropertyChangeListener(listener); 058 } 059}