39 | * As specified in {@link Throwable}, the message in the given cause
is not used in this instance's
40 | * message.
41 | *
56 | * The message is set to cause==null ? null : cause.toString()
, which by default contains the class
57 | * and message of cause
. This constructor is useful for call sites that just wrap another throwable.
58 | *
36 | * This method uses {@link Arrays#sort(Object[], Comparator)} 37 | * and returns the original array. 38 | * 39 | * @param files The files to sort, may be null 40 | * @return The sorted array 41 | * @since 2.0 42 | */ 43 | public File[] sort(File... files) { 44 | if (files != null) { 45 | Arrays.sort(files, this); 46 | } 47 | return files; 48 | } 49 | 50 | /** 51 | * Sort a List of files. 52 | *
53 | * This method uses {@link Collections#sort(List, Comparator)}
54 | * and returns the original list.
55 | *
56 | * @param files The files to sort, may be null
57 | * @return The sorted list
58 | * @since 2.0
59 | */
60 | public List
26 | * This comparator can be used to sort lists or arrays of files
27 | * by using the default file comparison.
28 | *
29 | * Example of sorting a list of files using the
30 | * {@link #DEFAULT_COMPARATOR} singleton instance:
31 | *
36 | * Example of doing a reverse sort of an array of files using the
37 | * {@link #DEFAULT_REVERSE} singleton instance:
38 | *
43 | *
44 | * @version $Id: DefaultFileComparator.java 1304052 2012-03-22 20:55:29Z ggregory $
45 | * @since 1.4
46 | */
47 | public class DefaultFileComparator extends AbstractFileComparator implements Serializable {
48 | private static final long serialVersionUID = 1L;
49 | /** Singleton default comparator instance */
50 | public static final Comparator
26 | * This comparator can be used to sort lists or arrays by directories and files.
27 | *
28 | * Example of sorting a list of files/directories using the
29 | * {@link #DIRECTORY_COMPARATOR} singleton instance:
30 | *
35 | * Example of doing a reverse sort of an array of files/directories using the
36 | * {@link #DIRECTORY_REVERSE} singleton instance:
37 | *
42 | *
43 | * @version $Id: DirectoryFileComparator.java 1304052 2012-03-22 20:55:29Z ggregory $
44 | * @since 2.0
45 | */
46 | public class DirectoryFileComparator extends AbstractFileComparator implements Serializable {
47 | private static final long serialVersionUID = 1L;
48 | /** Singleton default comparator instance */
49 | public static final Comparator
27 | * This comparator can be used to sort lists or arrays of files
28 | * by their last modified date/time.
29 | *
30 | * Example of sorting a list of files using the
31 | * {@link #LASTMODIFIED_COMPARATOR} singleton instance:
32 | *
37 | * Example of doing a reverse sort of an array of files using the
38 | * {@link #LASTMODIFIED_REVERSE} singleton instance:
39 | *
44 | *
45 | * @version $Id: LastModifiedFileComparator.java 1304052 2012-03-22 20:55:29Z ggregory $
46 | * @since 1.4
47 | */
48 | public class LastModifiedFileComparator extends AbstractFileComparator implements Serializable {
49 | private static final long serialVersionUID = 1L;
50 | /** Last modified comparator instance */
51 | public static final Comparator
25 | * Note that a subclass must override one of the accept methods,
26 | * otherwise your class will infinitely loop.
27 | *
28 | * @since 1.0
29 | * @version $Id: AbstractFileFilter.java 1304052 2012-03-22 20:55:29Z ggregory $
30 | */
31 | public abstract class AbstractFileFilter implements IOFileFilter {
32 |
33 | /**
34 | * Checks to see if the File should be accepted by this filter.
35 | *
36 | * @param file the File to check
37 | * @return true if this file matches the test
38 | */
39 | public boolean accept(File file) {
40 | return accept(file.getParentFile(), file.getName());
41 | }
42 |
43 | /**
44 | * Checks to see if the File should be accepted by this filter.
45 | *
46 | * @param dir the directory File to check
47 | * @param name the filename within the directory to check
48 | * @return true if this file matches the test
49 | */
50 | public boolean accept(File dir, String name) {
51 | return accept(new File(dir, name));
52 | }
53 |
54 | /**
55 | * Provide a String representaion of this file filter.
56 | *
57 | * @return a String representaion
58 | */
59 | @Override
60 | public String toString() {
61 | return getClass().getSimpleName();
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/filefilter/CanReadFileFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.filefilter;
18 |
19 | import java.io.File;
20 | import java.io.Serializable;
21 |
22 | /**
23 | * This filter accepts
25 | * Example, showing how to print out a list of the
26 | * current directory's readable files:
27 | *
28 | *
37 | * Example, showing how to print out a list of the
38 | * current directory's un-readable files:
39 | *
40 | *
49 | * Example, showing how to print out a list of the
50 | * current directory's read-only files:
51 | *
52 | *
25 | * Example, showing how to print out a list of the
26 | * current directory's writable files:
27 | *
28 | *
37 | * Example, showing how to print out a list of the
38 | * current directory's un-writable files:
39 | *
40 | *
49 | * N.B. For read-only files, use
50 | *
25 | * For example, here is how to print out a list of the
26 | * current directory's subdirectories:
27 | *
28 | *
25 | * If the
28 | * Example, showing how to print out a list of the
29 | * current directory's empty files/directories:
30 | *
31 | *
40 | * Example, showing how to print out a list of the
41 | * current directory's non-empty files/directories:
42 | *
43 | *
25 | * For example, here is how to print out a list of the real files
26 | * within the current directory:
27 | *
28 | *
25 | * Example, showing how to print out a list of the
26 | * current directory's hidden files:
27 | *
28 | *
37 | * Example, showing how to print out a list of the
38 | * current directory's visible (i.e. not hidden) files:
39 | *
40 | *
35 | * Defined in {@link java.io.FileFilter}.
36 | *
37 | * @param file the File to check
38 | * @return true if this file matches the test
39 | */
40 | boolean accept(File file);
41 |
42 | /**
43 | * Checks to see if the File should be accepted by this filter.
44 | *
45 | * Defined in {@link java.io.FilenameFilter}.
46 | *
47 | * @param dir the directory File to check
48 | * @param name the filename within the directory to check
49 | * @return true if this file matches the test
50 | */
51 | boolean accept(File dir, String name);
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/filefilter/NotFileFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.filefilter;
18 |
19 | import java.io.File;
20 | import java.io.Serializable;
21 |
22 | /**
23 | * This filter produces a logical NOT of the filters specified.
24 | *
25 | * @since 1.0
26 | * @version $Id: NotFileFilter.java 1304052 2012-03-22 20:55:29Z ggregory $
27 | * @see FileFilterUtils#notFileFilter(IOFileFilter)
28 | */
29 | public class NotFileFilter extends AbstractFileFilter implements Serializable {
30 | private static final long serialVersionUID = 1L;
31 | /** The filter */
32 | private final IOFileFilter filter;
33 |
34 | /**
35 | * Constructs a new file filter that NOTs the result of another filter.
36 | *
37 | * @param filter the filter, must not be null
38 | * @throws IllegalArgumentException if the filter is null
39 | */
40 | public NotFileFilter(IOFileFilter filter) {
41 | if (filter == null) {
42 | throw new IllegalArgumentException("The filter must not be null");
43 | }
44 | this.filter = filter;
45 | }
46 |
47 | /**
48 | * Returns the logical NOT of the underlying filter's return value for the same File.
49 | *
50 | * @param file the File to check
51 | * @return true if the filter returns false
52 | */
53 | @Override
54 | public boolean accept(File file) {
55 | return ! filter.accept(file);
56 | }
57 |
58 | /**
59 | * Returns the logical NOT of the underlying filter's return value for the same arguments.
60 | *
61 | * @param file the File directory
62 | * @param name the filename
63 | * @return true if the filter returns false
64 | */
65 | @Override
66 | public boolean accept(File file, String name) {
67 | return ! filter.accept(file, name);
68 | }
69 |
70 | /**
71 | * Provide a String representaion of this file filter.
72 | *
73 | * @return a String representaion
74 | */
75 | @Override
76 | public String toString() {
77 | return super.toString() + "(" + filter.toString() + ")";
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/filefilter/TrueFileFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.filefilter;
18 |
19 | import java.io.File;
20 | import java.io.Serializable;
21 |
22 | /**
23 | * A file filter that always returns true.
24 | *
25 | * @since 1.0
26 | * @version $Id: TrueFileFilter.java 1304058 2012-03-22 21:02:43Z sebb $
27 | * @see FileFilterUtils#trueFileFilter()
28 | */
29 | public class TrueFileFilter implements IOFileFilter, Serializable {
30 | private static final long serialVersionUID = 1L;
31 | /**
32 | * Singleton instance of true filter.
33 | * @since 1.3
34 | */
35 | public static final IOFileFilter TRUE = new TrueFileFilter();
36 | /**
37 | * Singleton instance of true filter.
38 | * Please use the identical TrueFileFilter.TRUE constant.
39 | * The new name is more JDK 1.5 friendly as it doesn't clash with other
40 | * values when using static imports.
41 | */
42 | public static final IOFileFilter INSTANCE = TRUE;
43 |
44 | /**
45 | * Restrictive consructor.
46 | */
47 | protected TrueFileFilter() {
48 | }
49 |
50 | /**
51 | * Returns true.
52 | *
53 | * @param file the file to check (ignored)
54 | * @return true
55 | */
56 | public boolean accept(File file) {
57 | return true;
58 | }
59 |
60 | /**
61 | * Returns true.
62 | *
63 | * @param dir the directory to check (ignored)
64 | * @param name the filename (ignored)
65 | * @return true
66 | */
67 | public boolean accept(File dir, String name) {
68 | return true;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/input/AutoCloseInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.input;
18 |
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 |
22 | /**
23 | * Proxy stream that closes and discards the underlying stream as soon as the
24 | * end of input has been reached or when the stream is explicitly closed.
25 | * Not even a reference to the underlying stream is kept after it has been
26 | * closed, so any allocated in-memory buffers can be freed even if the
27 | * client application still keeps a reference to the proxy stream.
28 | *
29 | * This class is typically used to release any resources related to an open
30 | * stream as soon as possible even if the client application (by not explicitly
31 | * closing the stream when no longer needed) or the underlying stream (by not
32 | * releasing resources once the last byte has been read) do not do that.
33 | *
34 | * @version $Id: AutoCloseInputStream.java 1304052 2012-03-22 20:55:29Z ggregory $
35 | * @since 1.4
36 | */
37 | public class AutoCloseInputStream extends ProxyInputStream {
38 |
39 | /**
40 | * Creates an automatically closing proxy for the given input stream.
41 | *
42 | * @param in underlying input stream
43 | */
44 | public AutoCloseInputStream(InputStream in) {
45 | super(in);
46 | }
47 |
48 | /**
49 | * Closes the underlying input stream and replaces the reference to it
50 | * with a {@link ClosedInputStream} instance.
51 | *
52 | * This method is automatically called by the read methods when the end
53 | * of input has been reached.
54 | *
55 | * Note that it is safe to call this method any number of times. The original
56 | * underlying input stream is closed and discarded only once when this
57 | * method is first called.
58 | *
59 | * @throws IOException if the underlying input stream can not be closed
60 | */
61 | @Override
62 | public void close() throws IOException {
63 | in.close();
64 | in = new ClosedInputStream();
65 | }
66 |
67 | /**
68 | * Automatically closes the stream if the end of stream was reached.
69 | *
70 | * @param n number of bytes read, or -1 if no more bytes are available
71 | * @throws IOException if the stream could not be closed
72 | * @since 2.0
73 | */
74 | @Override
75 | protected void afterRead(int n) throws IOException {
76 | if (n == -1) {
77 | close();
78 | }
79 | }
80 |
81 | /**
82 | * Ensures that the stream is closed before it gets garbage-collected.
83 | * As mentioned in {@link #close()}, this is a no-op if the stream has
84 | * already been closed.
85 | * @throws Throwable if an error occurs
86 | */
87 | @Override
88 | protected void finalize() throws Throwable {
89 | close();
90 | super.finalize();
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/input/BrokenInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.input;
18 |
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 |
22 | /**
23 | * Broken input stream. This stream always throws an {@link IOException} from
24 | * all the {@link InputStream} methods where the exception is declared.
25 | *
26 | * This class is mostly useful for testing error handling in code that uses an
27 | * input stream.
28 | *
29 | * @since 2.0
30 | */
31 | public class BrokenInputStream extends InputStream {
32 |
33 | /**
34 | * The exception that is thrown by all methods of this class.
35 | */
36 | private final IOException exception;
37 |
38 | /**
39 | * Creates a new stream that always throws the given exception.
40 | *
41 | * @param exception the exception to be thrown
42 | */
43 | public BrokenInputStream(IOException exception) {
44 | this.exception = exception;
45 | }
46 |
47 | /**
48 | * Creates a new stream that always throws an {@link IOException}
49 | */
50 | public BrokenInputStream() {
51 | this(new IOException("Broken input stream"));
52 | }
53 |
54 | /**
55 | * Throws the configured exception.
56 | *
57 | * @return nothing
58 | * @throws IOException always thrown
59 | */
60 | @Override
61 | public int read() throws IOException {
62 | throw exception;
63 | }
64 |
65 | /**
66 | * Throws the configured exception.
67 | *
68 | * @return nothing
69 | * @throws IOException always thrown
70 | */
71 | @Override
72 | public int available() throws IOException {
73 | throw exception;
74 | }
75 |
76 | /**
77 | * Throws the configured exception.
78 | *
79 | * @param n ignored
80 | * @return nothing
81 | * @throws IOException always thrown
82 | */
83 | @Override
84 | public long skip(long n) throws IOException {
85 | throw exception;
86 | }
87 |
88 | /**
89 | * Throws the configured exception.
90 | *
91 | * @throws IOException always thrown
92 | */
93 | @Override
94 | public void reset() throws IOException {
95 | throw exception;
96 | }
97 |
98 | /**
99 | * Throws the configured exception.
100 | *
101 | * @throws IOException always thrown
102 | */
103 | @Override
104 | public void close() throws IOException {
105 | throw exception;
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/input/CloseShieldInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.input;
18 |
19 | import java.io.InputStream;
20 |
21 | /**
22 | * Proxy stream that prevents the underlying input stream from being closed.
23 | *
24 | * This class is typically used in cases where an input stream needs to be
25 | * passed to a component that wants to explicitly close the stream even if
26 | * more input would still be available to other components.
27 | *
28 | * @version $Id: CloseShieldInputStream.java 1304052 2012-03-22 20:55:29Z ggregory $
29 | * @since 1.4
30 | */
31 | public class CloseShieldInputStream extends ProxyInputStream {
32 |
33 | /**
34 | * Creates a proxy that shields the given input stream from being
35 | * closed.
36 | *
37 | * @param in underlying input stream
38 | */
39 | public CloseShieldInputStream(InputStream in) {
40 | super(in);
41 | }
42 |
43 | /**
44 | * Replaces the underlying input stream with a {@link ClosedInputStream}
45 | * sentinel. The original input stream will remain open, but this proxy
46 | * will appear closed.
47 | */
48 | @Override
49 | public void close() {
50 | in = new ClosedInputStream();
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/input/ClosedInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.input;
18 |
19 | import java.io.InputStream;
20 |
21 | /**
22 | * Closed input stream. This stream returns -1 to all attempts to read
23 | * something from the stream.
24 | *
25 | * Typically uses of this class include testing for corner cases in methods
26 | * that accept input streams and acting as a sentinel value instead of a
27 | * {@code null} input stream.
28 | *
29 | * @version $Id: ClosedInputStream.java 1307459 2012-03-30 15:11:44Z ggregory $
30 | * @since 1.4
31 | */
32 | public class ClosedInputStream extends InputStream {
33 |
34 | /**
35 | * A singleton.
36 | */
37 | public static final ClosedInputStream CLOSED_INPUT_STREAM = new ClosedInputStream();
38 |
39 | /**
40 | * Returns -1 to indicate that the stream is closed.
41 | *
42 | * @return always -1
43 | */
44 | @Override
45 | public int read() {
46 | return -1;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/input/DemuxInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.input;
18 |
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 |
22 | /**
23 | * Data written to this stream is forwarded to a stream that has been associated
24 | * with this thread.
25 | *
26 | * @version $Id: DemuxInputStream.java 1302056 2012-03-18 03:03:38Z ggregory $
27 | */
28 | public class DemuxInputStream
29 | extends InputStream
30 | {
31 | private final InheritableThreadLocal
37 | * Note: this is called from the tailer thread.
38 | */
39 | void fileNotFound();
40 |
41 | /**
42 | * Called if a file rotation is detected.
43 | *
44 | * This method is called before the file is reopened, and fileNotFound may
45 | * be called if the new file has not yet been created.
46 | *
47 | * Note: this is called from the tailer thread.
48 | */
49 | void fileRotated();
50 |
51 | /**
52 | * Handles a line from a Tailer.
53 | *
54 | * Note: this is called from the tailer thread.
55 | * @param line the line.
56 | */
57 | void handle(String line);
58 |
59 | /**
60 | * Handles an Exception .
61 | *
62 | * Note: this is called from the tailer thread.
63 | * @param ex the exception.
64 | */
65 | void handle(Exception ex);
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/input/TailerListenerAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.input;
18 |
19 | /**
20 | * {@link TailerListener} Adapter.
21 | *
22 | * @version $Id: TailerListenerAdapter.java 1304052 2012-03-22 20:55:29Z ggregory $
23 | * @since 2.0
24 | */
25 | public class TailerListenerAdapter implements TailerListener {
26 |
27 | /**
28 | * The tailer will call this method during construction,
29 | * giving the listener a method of stopping the tailer.
30 | * @param tailer the tailer.
31 | */
32 | public void init(Tailer tailer) {
33 | }
34 |
35 | /**
36 | * This method is called if the tailed file is not found.
37 | */
38 | public void fileNotFound() {
39 | }
40 |
41 | /**
42 | * Called if a file rotation is detected.
43 | *
44 | * This method is called before the file is reopened, and fileNotFound may
45 | * be called if the new file has not yet been created.
46 | */
47 | public void fileRotated() {
48 | }
49 |
50 | /**
51 | * Handles a line from a Tailer.
52 | * @param line the line.
53 | */
54 | public void handle(String line) {
55 | }
56 |
57 | /**
58 | * Handles an Exception .
59 | * @param ex the exception.
60 | */
61 | public void handle(Exception ex) {
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/monitor/FileAlterationListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.monitor;
18 | import java.io.File;
19 |
20 | /**
21 | * A listener that receives events of file system modifications.
22 | *
23 | * Register {@link FileAlterationListener}s with a {@link FileAlterationObserver}.
24 | *
25 | * @see FileAlterationObserver
26 | * @version $Id: FileAlterationListener.java 1304052 2012-03-22 20:55:29Z ggregory $
27 | * @since 2.0
28 | */
29 | public interface FileAlterationListener {
30 |
31 | /**
32 | * File system observer started checking event.
33 | *
34 | * @param observer The file system observer
35 | */
36 | void onStart(final FileAlterationObserver observer);
37 |
38 | /**
39 | * Directory created Event.
40 | *
41 | * @param directory The directory created
42 | */
43 | void onDirectoryCreate(final File directory);
44 |
45 | /**
46 | * Directory changed Event.
47 | *
48 | * @param directory The directory changed
49 | */
50 | void onDirectoryChange(final File directory);
51 |
52 | /**
53 | * Directory deleted Event.
54 | *
55 | * @param directory The directory deleted
56 | */
57 | void onDirectoryDelete(final File directory);
58 |
59 | /**
60 | * File created Event.
61 | *
62 | * @param file The file created
63 | */
64 | void onFileCreate(final File file);
65 |
66 | /**
67 | * File changed Event.
68 | *
69 | * @param file The file changed
70 | */
71 | void onFileChange(final File file);
72 |
73 | /**
74 | * File deleted Event.
75 | *
76 | * @param file The file deleted
77 | */
78 | void onFileDelete(final File file);
79 |
80 | /**
81 | * File system observer finished checking event.
82 | *
83 | * @param observer The file system observer
84 | */
85 | void onStop(final FileAlterationObserver observer);
86 | }
87 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/monitor/FileAlterationListenerAdaptor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.monitor;
18 |
19 | import java.io.File;
20 |
21 | /**
22 | * Convenience {@link FileAlterationListener} implementation that does nothing.
23 | *
24 | * @see FileAlterationObserver
25 | * @version $Id: FileAlterationListenerAdaptor.java 1304062 2012-03-22 21:10:46Z sebb $
26 | * @since 2.0
27 | */
28 | public class FileAlterationListenerAdaptor implements FileAlterationListener {
29 |
30 | /**
31 | * File system observer started checking event.
32 | *
33 | * @param observer The file system observer (ignored)
34 | */
35 | public void onStart(final FileAlterationObserver observer) {
36 | }
37 |
38 | /**
39 | * Directory created Event.
40 | *
41 | * @param directory The directory created (ignored)
42 | */
43 | public void onDirectoryCreate(final File directory) {
44 | }
45 |
46 | /**
47 | * Directory changed Event.
48 | *
49 | * @param directory The directory changed (ignored)
50 | */
51 | public void onDirectoryChange(final File directory) {
52 | }
53 |
54 | /**
55 | * Directory deleted Event.
56 | *
57 | * @param directory The directory deleted (ignored)
58 | */
59 | public void onDirectoryDelete(final File directory) {
60 | }
61 |
62 | /**
63 | * File created Event.
64 | *
65 | * @param file The file created (ignored)
66 | */
67 | public void onFileCreate(final File file) {
68 | }
69 |
70 | /**
71 | * File changed Event.
72 | *
73 | * @param file The file changed (ignored)
74 | */
75 | public void onFileChange(final File file) {
76 | }
77 |
78 | /**
79 | * File deleted Event.
80 | *
81 | * @param file The file deleted (ignored)
82 | */
83 | public void onFileDelete(final File file) {
84 | }
85 |
86 | /**
87 | * File system observer finished checking event.
88 | *
89 | * @param observer The file system observer (ignored)
90 | */
91 | public void onStop(final FileAlterationObserver observer) {
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/output/BrokenOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.output;
18 |
19 | import java.io.IOException;
20 | import java.io.OutputStream;
21 |
22 | /**
23 | * Broken output stream. This stream always throws an {@link IOException} from
24 | * all {@link OutputStream} methods.
25 | *
26 | * This class is mostly useful for testing error handling in code that uses an
27 | * output stream.
28 | *
29 | * @since 2.0
30 | */
31 | public class BrokenOutputStream extends OutputStream {
32 |
33 | /**
34 | * The exception that is thrown by all methods of this class.
35 | */
36 | private final IOException exception;
37 |
38 | /**
39 | * Creates a new stream that always throws the given exception.
40 | *
41 | * @param exception the exception to be thrown
42 | */
43 | public BrokenOutputStream(IOException exception) {
44 | this.exception = exception;
45 | }
46 |
47 | /**
48 | * Creates a new stream that always throws an {@link IOException}
49 | */
50 | public BrokenOutputStream() {
51 | this(new IOException("Broken output stream"));
52 | }
53 |
54 | /**
55 | * Throws the configured exception.
56 | *
57 | * @param b ignored
58 | * @throws IOException always thrown
59 | */
60 | @Override
61 | public void write(int b) throws IOException {
62 | throw exception;
63 | }
64 |
65 | /**
66 | * Throws the configured exception.
67 | *
68 | * @throws IOException always thrown
69 | */
70 | @Override
71 | public void flush() throws IOException {
72 | throw exception;
73 | }
74 |
75 | /**
76 | * Throws the configured exception.
77 | *
78 | * @throws IOException always thrown
79 | */
80 | @Override
81 | public void close() throws IOException {
82 | throw exception;
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/output/CloseShieldOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.output;
18 |
19 | import java.io.OutputStream;
20 |
21 | /**
22 | * Proxy stream that prevents the underlying output stream from being closed.
23 | *
24 | * This class is typically used in cases where an output stream needs to be
25 | * passed to a component that wants to explicitly close the stream even if
26 | * other components would still use the stream for output.
27 | *
28 | * @version $Id: CloseShieldOutputStream.java 1304052 2012-03-22 20:55:29Z ggregory $
29 | * @since 1.4
30 | */
31 | public class CloseShieldOutputStream extends ProxyOutputStream {
32 |
33 | /**
34 | * Creates a proxy that shields the given output stream from being
35 | * closed.
36 | *
37 | * @param out underlying output stream
38 | */
39 | public CloseShieldOutputStream(OutputStream out) {
40 | super(out);
41 | }
42 |
43 | /**
44 | * Replaces the underlying output stream with a {@link ClosedOutputStream}
45 | * sentinel. The original output stream will remain open, but this proxy
46 | * will appear closed.
47 | */
48 | @Override
49 | public void close() {
50 | out = new ClosedOutputStream();
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/output/ClosedOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.output;
18 |
19 | import java.io.IOException;
20 | import java.io.OutputStream;
21 |
22 | /**
23 | * Closed output stream. This stream throws an exception on all attempts to
24 | * write something to the stream.
25 | *
26 | * Typically uses of this class include testing for corner cases in methods
27 | * that accept an output stream and acting as a sentinel value instead of
28 | * a {@code null} output stream.
29 | *
30 | * @version $Id: ClosedOutputStream.java 1307459 2012-03-30 15:11:44Z ggregory $
31 | * @since 1.4
32 | */
33 | public class ClosedOutputStream extends OutputStream {
34 |
35 | /**
36 | * A singleton.
37 | */
38 | public static final ClosedOutputStream CLOSED_OUTPUT_STREAM = new ClosedOutputStream();
39 |
40 | /**
41 | * Throws an {@link IOException} to indicate that the stream is closed.
42 | *
43 | * @param b ignored
44 | * @throws IOException always thrown
45 | */
46 | @Override
47 | public void write(int b) throws IOException {
48 | throw new IOException("write(" + b + ") failed: stream is closed");
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/output/DemuxOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.output;
18 |
19 | import java.io.IOException;
20 | import java.io.OutputStream;
21 |
22 | /**
23 | * Data written to this stream is forwarded to a stream that has been associated
24 | * with this thread.
25 | *
26 | * @version $Id: DemuxOutputStream.java 1302056 2012-03-18 03:03:38Z ggregory $
27 | */
28 | public class DemuxOutputStream
29 | extends OutputStream
30 | {
31 | private final InheritableThreadLocal
25 | * This output stream has no destination (file/socket etc.) and all
26 | * bytes written to it are ignored and lost.
27 | *
28 | * @version $Id: NullOutputStream.java 1302056 2012-03-18 03:03:38Z ggregory $
29 | */
30 | public class NullOutputStream extends OutputStream {
31 |
32 | /**
33 | * A singleton.
34 | */
35 | public static final NullOutputStream NULL_OUTPUT_STREAM = new NullOutputStream();
36 |
37 | /**
38 | * Does nothing - output to
32 | * List<File> list = ...
33 | * DefaultFileComparator.DEFAULT_COMPARATOR.sort(list);
34 | *
35 | *
39 | * File[] array = ...
40 | * DefaultFileComparator.DEFAULT_REVERSE.sort(array);
41 | *
42 | *
31 | * List<File> list = ...
32 | * DirectoryFileComparator.DIRECTORY_COMPARATOR.sort(list);
33 | *
34 | *
38 | * File[] array = ...
39 | * DirectoryFileComparator.DIRECTORY_REVERSE.sort(array);
40 | *
41 | *
33 | * List<File> list = ...
34 | * LastModifiedFileComparator.LASTMODIFIED_COMPARATOR.sort(list);
35 | *
36 | *
40 | * File[] array = ...
41 | * LastModifiedFileComparator.LASTMODIFIED_REVERSE.sort(array);
42 | *
43 | * File
s that can be read.
24 | *
29 | * File dir = new File(".");
30 | * String[] files = dir.list( CanReadFileFilter.CAN_READ );
31 | * for ( int i = 0; i < files.length; i++ ) {
32 | * System.out.println(files[i]);
33 | * }
34 | *
35 | *
36 | *
41 | * File dir = new File(".");
42 | * String[] files = dir.list( CanReadFileFilter.CANNOT_READ );
43 | * for ( int i = 0; i < files.length; i++ ) {
44 | * System.out.println(files[i]);
45 | * }
46 | *
47 | *
48 | *
53 | * File dir = new File(".");
54 | * String[] files = dir.list( CanReadFileFilter.READ_ONLY );
55 | * for ( int i = 0; i < files.length; i++ ) {
56 | * System.out.println(files[i]);
57 | * }
58 | *
59 | *
60 | * @since 1.3
61 | * @version $Id: CanReadFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $
62 | */
63 | public class CanReadFileFilter extends AbstractFileFilter implements Serializable {
64 | private static final long serialVersionUID = 1L;
65 | /** Singleton instance of readable filter */
66 | public static final IOFileFilter CAN_READ = new CanReadFileFilter();
67 |
68 | /** Singleton instance of not readable filter */
69 | public static final IOFileFilter CANNOT_READ = new NotFileFilter(CAN_READ);
70 |
71 | /** Singleton instance of read-only filter */
72 | public static final IOFileFilter READ_ONLY = new AndFileFilter(CAN_READ,
73 | CanWriteFileFilter.CANNOT_WRITE);
74 |
75 | /**
76 | * Restrictive consructor.
77 | */
78 | protected CanReadFileFilter() {
79 | }
80 |
81 | /**
82 | * Checks to see if the file can be read.
83 | *
84 | * @param file the File to check.
85 | * @return {@code true} if the file can be
86 | * read, otherwise {@code false}.
87 | */
88 | @Override
89 | public boolean accept(File file) {
90 | return file.canRead();
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/filefilter/CanWriteFileFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.filefilter;
18 |
19 | import java.io.File;
20 | import java.io.Serializable;
21 |
22 | /**
23 | * This filter accepts File
s that can be written to.
24 | *
29 | * File dir = new File(".");
30 | * String[] files = dir.list( CanWriteFileFilter.CAN_WRITE );
31 | * for ( int i = 0; i < files.length; i++ ) {
32 | * System.out.println(files[i]);
33 | * }
34 | *
35 | *
36 | *
41 | * File dir = new File(".");
42 | * String[] files = dir.list( CanWriteFileFilter.CANNOT_WRITE );
43 | * for ( int i = 0; i < files.length; i++ ) {
44 | * System.out.println(files[i]);
45 | * }
46 | *
47 | *
48 | * CanReadFileFilter.READ_ONLY
.
51 | *
52 | * @since 1.3
53 | * @version $Id: CanWriteFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $
54 | */
55 | public class CanWriteFileFilter extends AbstractFileFilter implements Serializable {
56 | private static final long serialVersionUID = 1L;
57 | /** Singleton instance of writable filter */
58 | public static final IOFileFilter CAN_WRITE = new CanWriteFileFilter();
59 |
60 | /** Singleton instance of not writable filter */
61 | public static final IOFileFilter CANNOT_WRITE = new NotFileFilter(CAN_WRITE);
62 |
63 | /**
64 | * Restrictive consructor.
65 | */
66 | protected CanWriteFileFilter() {
67 | }
68 |
69 | /**
70 | * Checks to see if the file can be written to.
71 | *
72 | * @param file the File to check
73 | * @return {@code true} if the file can be
74 | * written to, otherwise {@code false}.
75 | */
76 | @Override
77 | public boolean accept(File file) {
78 | return file.canWrite();
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/filefilter/ConditionalFileFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.filefilter;
18 |
19 | import java.util.List;
20 |
21 | /**
22 | * Defines operations for conditional file filters.
23 | *
24 | * @since 1.1
25 | * @version $Id: ConditionalFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $
26 | */
27 | public interface ConditionalFileFilter {
28 |
29 | /**
30 | * Adds the specified file filter to the list of file filters at the end of
31 | * the list.
32 | *
33 | * @param ioFileFilter the filter to be added
34 | * @since 1.1
35 | */
36 | void addFileFilter(IOFileFilter ioFileFilter);
37 |
38 | /**
39 | * Returns this conditional file filter's list of file filters.
40 | *
41 | * @return the file filter list
42 | * @since 1.1
43 | */
44 | ListFile
s that are directories.
24 | *
29 | * File dir = new File(".");
30 | * String[] files = dir.list( DirectoryFileFilter.INSTANCE );
31 | * for ( int i = 0; i < files.length; i++ ) {
32 | * System.out.println(files[i]);
33 | * }
34 | *
35 | *
36 | * @since 1.0
37 | * @version $Id: DirectoryFileFilter.java 1304052 2012-03-22 20:55:29Z ggregory $
38 | *
39 | * @see FileFilterUtils#directoryFileFilter()
40 | */
41 | public class DirectoryFileFilter extends AbstractFileFilter implements Serializable {
42 | private static final long serialVersionUID = 1L;
43 | /**
44 | * Singleton instance of directory filter.
45 | * @since 1.3
46 | */
47 | public static final IOFileFilter DIRECTORY = new DirectoryFileFilter();
48 | /**
49 | * Singleton instance of directory filter.
50 | * Please use the identical DirectoryFileFilter.DIRECTORY constant.
51 | * The new name is more JDK 1.5 friendly as it doesn't clash with other
52 | * values when using static imports.
53 | */
54 | public static final IOFileFilter INSTANCE = DIRECTORY;
55 |
56 | /**
57 | * Restrictive consructor.
58 | */
59 | protected DirectoryFileFilter() {
60 | }
61 |
62 | /**
63 | * Checks to see if the file is a directory.
64 | *
65 | * @param file the File to check
66 | * @return true if the file is a directory
67 | */
68 | @Override
69 | public boolean accept(File file) {
70 | return file.isDirectory();
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/filefilter/EmptyFileFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.filefilter;
18 |
19 | import java.io.File;
20 | import java.io.Serializable;
21 |
22 | /**
23 | * This filter accepts files or directories that are empty.
24 | * File
is a directory it checks that
26 | * it contains no files.
27 | *
32 | * File dir = new File(".");
33 | * String[] files = dir.list( EmptyFileFilter.EMPTY );
34 | * for ( int i = 0; i < files.length; i++ ) {
35 | * System.out.println(files[i]);
36 | * }
37 | *
38 | *
39 | *
44 | * File dir = new File(".");
45 | * String[] files = dir.list( EmptyFileFilter.NOT_EMPTY );
46 | * for ( int i = 0; i < files.length; i++ ) {
47 | * System.out.println(files[i]);
48 | * }
49 | *
50 | *
51 | * @since 1.3
52 | * @version $Id: EmptyFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $
53 | */
54 | public class EmptyFileFilter extends AbstractFileFilter implements Serializable {
55 | private static final long serialVersionUID = 1L;
56 | /** Singleton instance of empty filter */
57 | public static final IOFileFilter EMPTY = new EmptyFileFilter();
58 |
59 | /** Singleton instance of not-empty filter */
60 | public static final IOFileFilter NOT_EMPTY = new NotFileFilter(EMPTY);
61 |
62 | /**
63 | * Restrictive consructor.
64 | */
65 | protected EmptyFileFilter() {
66 | }
67 |
68 | /**
69 | * Checks to see if the file is empty.
70 | *
71 | * @param file the file or directory to check
72 | * @return {@code true} if the file or directory
73 | * is empty, otherwise {@code false}.
74 | */
75 | @Override
76 | public boolean accept(File file) {
77 | if (file.isDirectory()) {
78 | File[] files = file.listFiles();
79 | return files == null || files.length == 0;
80 | } else {
81 | return file.length() == 0;
82 | }
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/filefilter/FalseFileFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.filefilter;
18 |
19 | import java.io.File;
20 | import java.io.Serializable;
21 |
22 | /**
23 | * A file filter that always returns false.
24 | *
25 | * @since 1.0
26 | * @version $Id: FalseFileFilter.java 1304058 2012-03-22 21:02:43Z sebb $
27 | *
28 | * @see FileFilterUtils#falseFileFilter()
29 | */
30 | public class FalseFileFilter implements IOFileFilter, Serializable {
31 | private static final long serialVersionUID = 1L;
32 | /**
33 | * Singleton instance of false filter.
34 | * @since 1.3
35 | */
36 | public static final IOFileFilter FALSE = new FalseFileFilter();
37 | /**
38 | * Singleton instance of false filter.
39 | * Please use the identical FalseFileFilter.FALSE constant.
40 | * The new name is more JDK 1.5 friendly as it doesn't clash with other
41 | * values when using static imports.
42 | */
43 | public static final IOFileFilter INSTANCE = FALSE;
44 |
45 | /**
46 | * Restrictive consructor.
47 | */
48 | protected FalseFileFilter() {
49 | }
50 |
51 | /**
52 | * Returns false.
53 | *
54 | * @param file the file to check (ignored)
55 | * @return false
56 | */
57 | public boolean accept(File file) {
58 | return false;
59 | }
60 |
61 | /**
62 | * Returns false.
63 | *
64 | * @param dir the directory to check (ignored)
65 | * @param name the filename (ignored)
66 | * @return false
67 | */
68 | public boolean accept(File dir, String name) {
69 | return false;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/filefilter/FileFileFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.filefilter;
18 |
19 | import java.io.File;
20 | import java.io.Serializable;
21 |
22 | /**
23 | * This filter accepts File
s that are files (not directories).
24 | *
29 | * File dir = new File(".");
30 | * String[] files = dir.list( FileFileFilter.FILE );
31 | * for ( int i = 0; i < files.length; i++ ) {
32 | * System.out.println(files[i]);
33 | * }
34 | *
35 | *
36 | * @since 1.3
37 | * @version $Id: FileFileFilter.java 1304052 2012-03-22 20:55:29Z ggregory $
38 | * @see FileFilterUtils#fileFileFilter()
39 | */
40 | public class FileFileFilter extends AbstractFileFilter implements Serializable {
41 | private static final long serialVersionUID = 1L;
42 | /** Singleton instance of file filter */
43 | public static final IOFileFilter FILE = new FileFileFilter();
44 |
45 | /**
46 | * Restrictive consructor.
47 | */
48 | protected FileFileFilter() {
49 | }
50 |
51 | /**
52 | * Checks to see if the file is a file.
53 | *
54 | * @param file the File to check
55 | * @return true if the file is a file
56 | */
57 | @Override
58 | public boolean accept(File file) {
59 | return file.isFile();
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/filefilter/HiddenFileFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.filefilter;
18 |
19 | import java.io.File;
20 | import java.io.Serializable;
21 |
22 | /**
23 | * This filter accepts File
s that are hidden.
24 | *
29 | * File dir = new File(".");
30 | * String[] files = dir.list( HiddenFileFilter.HIDDEN );
31 | * for ( int i = 0; i < files.length; i++ ) {
32 | * System.out.println(files[i]);
33 | * }
34 | *
35 | *
36 | *
41 | * File dir = new File(".");
42 | * String[] files = dir.list( HiddenFileFilter.VISIBLE );
43 | * for ( int i = 0; i < files.length; i++ ) {
44 | * System.out.println(files[i]);
45 | * }
46 | *
47 | *
48 | * @since 1.3
49 | * @version $Id: HiddenFileFilter.java 1307462 2012-03-30 15:13:11Z ggregory $
50 | */
51 | public class HiddenFileFilter extends AbstractFileFilter implements Serializable {
52 | private static final long serialVersionUID = 1L;
53 | /** Singleton instance of hidden filter */
54 | public static final IOFileFilter HIDDEN = new HiddenFileFilter();
55 |
56 | /** Singleton instance of visible filter */
57 | public static final IOFileFilter VISIBLE = new NotFileFilter(HIDDEN);
58 |
59 | /**
60 | * Restrictive consructor.
61 | */
62 | protected HiddenFileFilter() {
63 | }
64 |
65 | /**
66 | * Checks to see if the file is hidden.
67 | *
68 | * @param file the File to check
69 | * @return {@code true} if the file is
70 | * hidden, otherwise {@code false}.
71 | */
72 | @Override
73 | public boolean accept(File file) {
74 | return file.isHidden();
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/filefilter/IOFileFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.filefilter;
18 |
19 | import java.io.File;
20 | import java.io.FileFilter;
21 | import java.io.FilenameFilter;
22 |
23 | /**
24 | * An interface which brings the FileFilter and FilenameFilter
25 | * interfaces together.
26 | *
27 | * @since 1.0
28 | * @version $Id: IOFileFilter.java 1304052 2012-03-22 20:55:29Z ggregory $
29 | */
30 | public interface IOFileFilter extends FileFilter, FilenameFilter {
31 |
32 | /**
33 | * Checks to see if the File should be accepted by this filter.
34 | * /dev/null
.
39 | * @param b The bytes to write
40 | * @param off The start offset
41 | * @param len The number of bytes to write
42 | */
43 | @Override
44 | public void write(byte[] b, int off, int len) {
45 | //to /dev/null
46 | }
47 |
48 | /**
49 | * Does nothing - output to /dev/null
.
50 | * @param b The byte to write
51 | */
52 | @Override
53 | public void write(int b) {
54 | //to /dev/null
55 | }
56 |
57 | /**
58 | * Does nothing - output to /dev/null
.
59 | * @param b The bytes to write
60 | * @throws IOException never
61 | */
62 | @Override
63 | public void write(byte[] b) throws IOException {
64 | //to /dev/null
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/org/apache/commons/io/output/TeeOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.io.output;
18 |
19 | import java.io.IOException;
20 | import java.io.OutputStream;
21 |
22 | /**
23 | * Classic splitter of OutputStream. Named after the unix 'tee'
24 | * command. It allows a stream to be branched off so there
25 | * are now two streams.
26 | *
27 | * @version $Id: TeeOutputStream.java 1302056 2012-03-18 03:03:38Z ggregory $
28 | */
29 | public class TeeOutputStream extends ProxyOutputStream {
30 |
31 | /** the second OutputStream to write to */
32 | protected OutputStream branch;
33 |
34 | /**
35 | * Constructs a TeeOutputStream.
36 | * @param out the main OutputStream
37 | * @param branch the second OutputStream
38 | */
39 | public TeeOutputStream(OutputStream out, OutputStream branch) {
40 | super(out);
41 | this.branch = branch;
42 | }
43 |
44 | /**
45 | * Write the bytes to both streams.
46 | * @param b the bytes to write
47 | * @throws IOException if an I/O error occurs
48 | */
49 | @Override
50 | public synchronized void write(byte[] b) throws IOException {
51 | super.write(b);
52 | this.branch.write(b);
53 | }
54 |
55 | /**
56 | * Write the specified bytes to both streams.
57 | * @param b the bytes to write
58 | * @param off The start offset
59 | * @param len The number of bytes to write
60 | * @throws IOException if an I/O error occurs
61 | */
62 | @Override
63 | public synchronized void write(byte[] b, int off, int len) throws IOException {
64 | super.write(b, off, len);
65 | this.branch.write(b, off, len);
66 | }
67 |
68 | /**
69 | * Write a byte to both streams.
70 | * @param b the byte to write
71 | * @throws IOException if an I/O error occurs
72 | */
73 | @Override
74 | public synchronized void write(int b) throws IOException {
75 | super.write(b);
76 | this.branch.write(b);
77 | }
78 |
79 | /**
80 | * Flushes both streams.
81 | * @throws IOException if an I/O error occurs
82 | */
83 | @Override
84 | public void flush() throws IOException {
85 | super.flush();
86 | this.branch.flush();
87 | }
88 |
89 | /**
90 | * Closes both output streams.
91 | *
92 | * If closing the main output stream throws an exception, attempt to close the branch output stream.
93 | *
94 | * If closing the main and branch output streams both throw exceptions, which exceptions is thrown by this method is
95 | * currently unspecified and subject to change.
96 | *
97 | * @throws IOException
98 | * if an I/O error occurs
99 | */
100 | @Override
101 | public void close() throws IOException {
102 | try {
103 | super.close();
104 | } finally {
105 | this.branch.close();
106 | }
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/src/org/objectweb/asm/Edge.java:
--------------------------------------------------------------------------------
1 | /***
2 | * ASM: a very small and fast Java bytecode manipulation framework
3 | * Copyright (c) 2000-2011 INRIA, France Telecom
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of the copyright holders nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 | * THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | package org.objectweb.asm;
31 |
32 | /**
33 | * An edge in the control flow graph of a method body. See {@link Label Label}.
34 | *
35 | * @author Eric Bruneton
36 | */
37 | class Edge {
38 |
39 | /**
40 | * Denotes a normal control flow graph edge.
41 | */
42 | static final int NORMAL = 0;
43 |
44 | /**
45 | * Denotes a control flow graph edge corresponding to an exception handler.
46 | * More precisely any {@link Edge} whose {@link #info} is strictly positive
47 | * corresponds to an exception handler. The actual value of {@link #info} is
48 | * the index, in the {@link ClassWriter} type table, of the exception that
49 | * is catched.
50 | */
51 | static final int EXCEPTION = 0x7FFFFFFF;
52 |
53 | /**
54 | * Information about this control flow graph edge. If
55 | * {@link ClassWriter#COMPUTE_MAXS} is used this field is the (relative)
56 | * stack size in the basic block from which this edge originates. This size
57 | * is equal to the stack size at the "jump" instruction to which this edge
58 | * corresponds, relatively to the stack size at the beginning of the
59 | * originating basic block. If {@link ClassWriter#COMPUTE_FRAMES} is used,
60 | * this field is the kind of this control flow graph edge (i.e. NORMAL or
61 | * EXCEPTION).
62 | */
63 | int info;
64 |
65 | /**
66 | * The successor block of the basic block from which this edge originates.
67 | */
68 | Label successor;
69 |
70 | /**
71 | * The next edge in the list of successors of the originating basic block.
72 | * See {@link Label#successors successors}.
73 | */
74 | Edge next;
75 | }
76 |
--------------------------------------------------------------------------------
/src/org/objectweb/asm/commons/AnnotationRemapper.java:
--------------------------------------------------------------------------------
1 | /***
2 | * ASM: a very small and fast Java bytecode manipulation framework
3 | * Copyright (c) 2000-2011 INRIA, France Telecom
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of the copyright holders nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 | * THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package org.objectweb.asm.commons;
32 |
33 | import org.objectweb.asm.AnnotationVisitor;
34 | import org.objectweb.asm.Opcodes;
35 |
36 | /**
37 | * An {@link AnnotationVisitor} adapter for type remapping.
38 | *
39 | * @author Eugene Kuleshov
40 | */
41 | public class AnnotationRemapper extends AnnotationVisitor {
42 |
43 | protected final Remapper remapper;
44 |
45 | public AnnotationRemapper(final AnnotationVisitor av,
46 | final Remapper remapper) {
47 | this(Opcodes.ASM5, av, remapper);
48 | }
49 |
50 | protected AnnotationRemapper(final int api, final AnnotationVisitor av,
51 | final Remapper remapper) {
52 | super(api, av);
53 | this.remapper = remapper;
54 | }
55 |
56 | @Override
57 | public void visit(String name, Object value) {
58 | av.visit(name, remapper.mapValue(value));
59 | }
60 |
61 | @Override
62 | public void visitEnum(String name, String desc, String value) {
63 | av.visitEnum(name, remapper.mapDesc(desc), value);
64 | }
65 |
66 | @Override
67 | public AnnotationVisitor visitAnnotation(String name, String desc) {
68 | AnnotationVisitor v = av.visitAnnotation(name, remapper.mapDesc(desc));
69 | return v == null ? null : (v == av ? this : new AnnotationRemapper(v,
70 | remapper));
71 | }
72 |
73 | @Override
74 | public AnnotationVisitor visitArray(String name) {
75 | AnnotationVisitor v = av.visitArray(name);
76 | return v == null ? null : (v == av ? this : new AnnotationRemapper(v,
77 | remapper));
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/org/objectweb/asm/commons/FieldRemapper.java:
--------------------------------------------------------------------------------
1 | /***
2 | * ASM: a very small and fast Java bytecode manipulation framework
3 | * Copyright (c) 2000-2011 INRIA, France Telecom
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of the copyright holders nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 | * THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package org.objectweb.asm.commons;
32 |
33 | import org.objectweb.asm.AnnotationVisitor;
34 | import org.objectweb.asm.FieldVisitor;
35 | import org.objectweb.asm.Opcodes;
36 | import org.objectweb.asm.TypePath;
37 |
38 | /**
39 | * A {@link FieldVisitor} adapter for type remapping.
40 | *
41 | * @author Eugene Kuleshov
42 | */
43 | public class FieldRemapper extends FieldVisitor {
44 |
45 | private final Remapper remapper;
46 |
47 | public FieldRemapper(final FieldVisitor fv, final Remapper remapper) {
48 | this(Opcodes.ASM5, fv, remapper);
49 | }
50 |
51 | protected FieldRemapper(final int api, final FieldVisitor fv,
52 | final Remapper remapper) {
53 | super(api, fv);
54 | this.remapper = remapper;
55 | }
56 |
57 | @Override
58 | public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
59 | AnnotationVisitor av = fv.visitAnnotation(remapper.mapDesc(desc),
60 | visible);
61 | return av == null ? null : new AnnotationRemapper(av, remapper);
62 | }
63 |
64 | @Override
65 | public AnnotationVisitor visitTypeAnnotation(int typeRef,
66 | TypePath typePath, String desc, boolean visible) {
67 | AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath,
68 | remapper.mapDesc(desc), visible);
69 | return av == null ? null : new AnnotationRemapper(av, remapper);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/org/objectweb/asm/commons/RemappingAnnotationAdapter.java:
--------------------------------------------------------------------------------
1 | /***
2 | * ASM: a very small and fast Java bytecode manipulation framework
3 | * Copyright (c) 2000-2011 INRIA, France Telecom
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of the copyright holders nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 | * THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package org.objectweb.asm.commons;
32 |
33 | import org.objectweb.asm.AnnotationVisitor;
34 | import org.objectweb.asm.Opcodes;
35 |
36 | /**
37 | * An {@link AnnotationVisitor} adapter for type remapping.
38 | *
39 | * @deprecated use {@link AnnotationRemapper} instead.
40 | * @author Eugene Kuleshov
41 | */
42 | @Deprecated
43 | public class RemappingAnnotationAdapter extends AnnotationVisitor {
44 |
45 | protected final Remapper remapper;
46 |
47 | public RemappingAnnotationAdapter(final AnnotationVisitor av,
48 | final Remapper remapper) {
49 | this(Opcodes.ASM5, av, remapper);
50 | }
51 |
52 | protected RemappingAnnotationAdapter(final int api,
53 | final AnnotationVisitor av, final Remapper remapper) {
54 | super(api, av);
55 | this.remapper = remapper;
56 | }
57 |
58 | @Override
59 | public void visit(String name, Object value) {
60 | av.visit(name, remapper.mapValue(value));
61 | }
62 |
63 | @Override
64 | public void visitEnum(String name, String desc, String value) {
65 | av.visitEnum(name, remapper.mapDesc(desc), value);
66 | }
67 |
68 | @Override
69 | public AnnotationVisitor visitAnnotation(String name, String desc) {
70 | AnnotationVisitor v = av.visitAnnotation(name, remapper.mapDesc(desc));
71 | return v == null ? null : (v == av ? this
72 | : new RemappingAnnotationAdapter(v, remapper));
73 | }
74 |
75 | @Override
76 | public AnnotationVisitor visitArray(String name) {
77 | AnnotationVisitor v = av.visitArray(name);
78 | return v == null ? null : (v == av ? this
79 | : new RemappingAnnotationAdapter(v, remapper));
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/org/objectweb/asm/commons/RemappingFieldAdapter.java:
--------------------------------------------------------------------------------
1 | /***
2 | * ASM: a very small and fast Java bytecode manipulation framework
3 | * Copyright (c) 2000-2011 INRIA, France Telecom
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of the copyright holders nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 | * THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package org.objectweb.asm.commons;
32 |
33 | import org.objectweb.asm.AnnotationVisitor;
34 | import org.objectweb.asm.FieldVisitor;
35 | import org.objectweb.asm.Opcodes;
36 | import org.objectweb.asm.TypePath;
37 |
38 | /**
39 | * A {@link FieldVisitor} adapter for type remapping.
40 | *
41 | * @deprecated use {@link FieldRemapper} instead.
42 | * @author Eugene Kuleshov
43 | */
44 | @Deprecated
45 | public class RemappingFieldAdapter extends FieldVisitor {
46 |
47 | private final Remapper remapper;
48 |
49 | public RemappingFieldAdapter(final FieldVisitor fv, final Remapper remapper) {
50 | this(Opcodes.ASM5, fv, remapper);
51 | }
52 |
53 | protected RemappingFieldAdapter(final int api, final FieldVisitor fv,
54 | final Remapper remapper) {
55 | super(api, fv);
56 | this.remapper = remapper;
57 | }
58 |
59 | @Override
60 | public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
61 | AnnotationVisitor av = fv.visitAnnotation(remapper.mapDesc(desc),
62 | visible);
63 | return av == null ? null : new RemappingAnnotationAdapter(av, remapper);
64 | }
65 |
66 | @Override
67 | public AnnotationVisitor visitTypeAnnotation(int typeRef,
68 | TypePath typePath, String desc, boolean visible) {
69 | AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath,
70 | remapper.mapDesc(desc), visible);
71 | return av == null ? null : new RemappingAnnotationAdapter(av, remapper);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/org/objectweb/asm/commons/SimpleRemapper.java:
--------------------------------------------------------------------------------
1 | /***
2 | * ASM: a very small and fast Java bytecode manipulation framework
3 | * Copyright (c) 2000-2011 INRIA, France Telecom
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of the copyright holders nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 | * THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package org.objectweb.asm.commons;
32 |
33 | import java.util.Collections;
34 | import java.util.Map;
35 |
36 | /**
37 | * A {@link Remapper} using a {@link Map} to define its mapping.
38 | *
39 | * @author Eugene Kuleshov
40 | */
41 | public class SimpleRemapper extends Remapper {
42 |
43 | private final Map