Skip to content

Commit de3b52d

Browse files
committed
Made closeable
1 parent 978b0a1 commit de3b52d

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.codehaus.plexus.components.io.resources;
2+
3+
import java.nio.charset.Charset;
4+
5+
/*
6+
* Copyright 2014 The Codehaus Foundation.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
/**
22+
* Implemented by plexus io resources that support some kind of encoding notion
23+
*/
24+
public interface EncodingSupported
25+
{
26+
/**
27+
* Supplies the encoding to be used for decoding filenames/paths
28+
* @param charset The charset to use
29+
*/
30+
public void setEncoding(Charset charset);
31+
}

Diff for: src/main/java/org/codehaus/plexus/components/io/resources/LinefeedMode.java

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
package org.codehaus.plexus.components.io.resources;
2+
/*
3+
* Copyright 2007 The Codehaus Foundation.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* 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+
*/
217

318
/**
419
* @author Kristian Rosenvold

Diff for: src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollection.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@
2626
import org.codehaus.plexus.components.io.functions.ResourceAttributeSupplier;
2727
import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResourceCollection;
2828
import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResourceCollectionWithAttributes;
29+
import org.codehaus.plexus.components.io.resources.EncodingSupported;
2930
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
3031
import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection;
3132
import org.codehaus.plexus.components.io.resources.Stream;
3233

3334
import javax.annotation.Nonnull;
3435
import java.io.IOException;
36+
import java.nio.charset.Charset;
3537
import java.util.Iterator;
3638

3739
/**
3840
* Implementation of {@link PlexusIoResourceCollection} for an archives contents.
3941
*/
4042
public class PlexusIoProxyResourceCollection
41-
extends AbstractPlexusIoResourceCollectionWithAttributes
43+
extends AbstractPlexusIoResourceCollectionWithAttributes implements EncodingSupported
4244
{
4345
private PlexusIoResourceCollection src;
4446

@@ -203,4 +205,11 @@ public long getLastModified()
203205
{
204206
return src.getLastModified();
205207
}
208+
209+
public void setEncoding( Charset charset )
210+
{
211+
if (src instanceof EncodingSupported){
212+
((EncodingSupported)src).setEncoding( charset );
213+
}
214+
}
206215
}

Diff for: src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19+
import java.io.Closeable;
1920
import java.io.File;
2021
import java.io.FileInputStream;
2122
import java.io.FileOutputStream;
@@ -158,7 +159,8 @@ private void testPlexusIoResourceCollection( PlexusIoResourceCollection plexusIo
158159
boolean yPathSeen = false;
159160
boolean aFileSeen = false;
160161
boolean bFileSeen = false;
161-
for ( Iterator iter = plexusIoResourceCollection.getResources(); iter.hasNext(); )
162+
Iterator iter = plexusIoResourceCollection.getResources();
163+
while ( iter.hasNext() )
162164
{
163165
PlexusIoResource res = (PlexusIoResource) iter.next();
164166
final String resName = res.getName().replace( File.separatorChar, '/' );
@@ -208,6 +210,10 @@ else if ( B_PATH.equals( resName ) )
208210

209211
assertTrue( aFileSeen );
210212
assertTrue( bFileSeen );
213+
if (iter instanceof Closeable)
214+
{
215+
( (Closeable) iter ).close();
216+
}
211217
}
212218

213219
private void testFileResourceCollection( PlexusIoFileResourceCollection resourceCollection )

0 commit comments

Comments
 (0)