01: /*
02: * ProGuard -- shrinking, optimization, obfuscation, and preverification
03: * of Java bytecode.
04: *
05: * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
06: *
07: * This program is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU General Public License as published by the Free
09: * Software Foundation; either version 2 of the License, or (at your option)
10: * any later version.
11: *
12: * This program is distributed in the hope that it will be useful, but WITHOUT
13: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15: * more details.
16: *
17: * You should have received a copy of the GNU General Public License along
18: * with this program; if not, write to the Free Software Foundation, Inc.,
19: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21: package proguard.io;
22:
23: import java.io.IOException;
24:
25: /**
26: * This DataEntryReader delegates to one of two other DataEntryReader instances,
27: * depending on whether the data entry passes through a given data entry filter
28: * or not.
29: *
30: * @author Eric Lafortune
31: */
32: public class FilteredDataEntryReader implements DataEntryReader {
33: private final DataEntryFilter dataEntryFilter;
34: private final DataEntryReader acceptedDataEntryReader;
35: private final DataEntryReader rejectedDataEntryReader;
36:
37: /**
38: * Creates a new FilteredDataEntryReader with only a reader for accepted
39: * data entries.
40: * @param dataEntryFilter the data entry filter.
41: * @param acceptedDataEntryReader the DataEntryReader to which the reading
42: * will be delegated if the filter accepts
43: * the data entry. May be <code>null</code>.
44: */
45: public FilteredDataEntryReader(DataEntryFilter dataEntryFilter,
46: DataEntryReader acceptedDataEntryReader) {
47: this (dataEntryFilter, acceptedDataEntryReader, null);
48: }
49:
50: /**
51: * Creates a new FilteredDataEntryReader.
52: * @param dataEntryFilter the data entry filter.
53: * @param acceptedDataEntryReader the DataEntryReader to which the reading
54: * will be delegated if the filter accepts
55: * the data entry. May be <code>null</code>.
56: * @param rejectedDataEntryReader the DataEntryReader to which the reading
57: * will be delegated if the filter does not
58: * accept the data entry. May be
59: * <code>null</code>.
60: */
61: public FilteredDataEntryReader(DataEntryFilter dataEntryFilter,
62: DataEntryReader acceptedDataEntryReader,
63: DataEntryReader rejectedDataEntryReader) {
64: this .dataEntryFilter = dataEntryFilter;
65: this .acceptedDataEntryReader = acceptedDataEntryReader;
66: this .rejectedDataEntryReader = rejectedDataEntryReader;
67: }
68:
69: // Implementations for DataEntryReader.
70:
71: public void read(DataEntry dataEntry) throws IOException {
72: DataEntryReader dataEntryReader = dataEntryFilter
73: .accepts(dataEntry) ? acceptedDataEntryReader
74: : rejectedDataEntryReader;
75:
76: if (dataEntryReader != null) {
77: dataEntryReader.read(dataEntry);
78: }
79: }
80: }
|