Skip to content

Commit b9fe235

Browse files
o Reformatted and updated to stop leaking file descriptors.
o Updated to stop creating 'BufferedInputStream' and 'BufferedOutputStream' when buffering is already taking place. o Updated to add missing '@deprecated' annotions and Javadoc tags.
1 parent 15a2246 commit b9fe235

File tree

6 files changed

+57
-38
lines changed

6 files changed

+57
-38
lines changed

src/main/java/org/codehaus/plexus/archiver/ArchiveEntry.java

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public String getName()
113113
* by files, but by instances of {@link PlexusIoResource}.
114114
* Consequently, you should use {@link #getInputStream()}-
115115
*/
116+
@Deprecated
116117
public File getFile()
117118
{
118119
if ( resource instanceof PlexusIoFileResource )

src/main/java/org/codehaus/plexus/archiver/Archiver.java

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void createArchive()
7878
* Obsolete, use {@link #addFileSet(FileSet)}.
7979
* You can use "inline" of this method in your
8080
* IDE to get the proper implementation for this release.
81+
* @deprecated Will go away in next major version
8182
*/
8283
@Deprecated
8384
void addDirectory( @Nonnull File directory )
@@ -87,6 +88,7 @@ void addDirectory( @Nonnull File directory )
8788
* Obsolete, use {@link #addFileSet(FileSet)}.
8889
* You can use "inline" of this method in your
8990
* IDE to get the proper implementation for this release.
91+
* @deprecated Will go away in next major version
9092
*/
9193
@Deprecated
9294
void addDirectory( @Nonnull File directory, String prefix )
@@ -95,6 +97,7 @@ void addDirectory( @Nonnull File directory, String prefix )
9597
/**
9698
* Obsolete, use {@link #addFileSet(FileSet)}.You can use "inline" of this method in your
9799
* IDE to get the proper implementation for this release.
100+
* @deprecated Will go away in next major version
98101
*/
99102
@Deprecated
100103
void addDirectory( @Nonnull File directory, String[] includes, String[] excludes )
@@ -104,7 +107,9 @@ void addDirectory( @Nonnull File directory, String[] includes, String[] excludes
104107
* Obsolete, use {@link #addFileSet(FileSet)}.
105108
* You can use "inline" of this method in your
106109
* IDE to get the proper implementation for this release.
110+
* @deprecated Will go away in next major version
107111
*/
112+
@Deprecated
108113
void addDirectory( @Nonnull File directory, String prefix, String[] includes, String[] excludes )
109114
throws ArchiverException;
110115

@@ -154,6 +159,7 @@ void addArchivedFileSet( @Nonnull File archiveFile, String prefix )
154159
* IDE to get the proper implementation for this release.
155160
* @deprecated Will go away in next major version
156161
*/
162+
@Deprecated
157163
void addArchivedFileSet( File archiveFile, String[] includes, String[] excludes )
158164
throws ArchiverException;
159165

@@ -162,6 +168,7 @@ void addArchivedFileSet( File archiveFile, String[] includes, String[] excludes
162168
* IDE to get the proper implementation for this release.
163169
* @deprecated Will go away in next major version
164170
*/
171+
@Deprecated
165172
void addArchivedFileSet( @Nonnull File archiveFile, String prefix, String[] includes, String[] excludes )
166173
throws ArchiverException;
167174

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.codehaus.plexus.archiver;
22

33
import org.codehaus.plexus.util.FileUtils;
4+
import org.codehaus.plexus.util.IOUtil;
45
import org.codehaus.plexus.util.StringUtils;
56

67
import java.io.File;
@@ -10,9 +11,8 @@
1011
import java.util.Collections;
1112
import java.util.List;
1213

13-
1414
/**
15-
* An @{link ArchiveFinalizer} that process dot files with archiver directives
15+
* An {@link ArchiveFinalizer} that process dot files with archiver directives
1616
* contained within. This basically means you can communicate archive creation
1717
* instructions between processes using dot files.
1818
*
@@ -21,6 +21,7 @@
2121
public class DotDirectiveArchiveFinalizer
2222
extends AbstractArchiveFinalizer
2323
{
24+
2425
private static final String DEFAULT_DOT_FILE_PREFIX = ".plxarc";
2526

2627
private final File dotFileDirectory;
@@ -42,51 +43,63 @@ public DotDirectiveArchiveFinalizer( File dotFileDirectory, String dotFilePrefix
4243
public void finalizeArchiveCreation( Archiver archiver )
4344
throws ArchiverException
4445
{
46+
BufferedReader in = null;
4547
try
4648
{
4749
List dotFiles = FileUtils.getFiles( dotFileDirectory, dotFilePrefix + "*", null );
4850

49-
for (Object dotFile1 : dotFiles) {
50-
File dotFile = (File) dotFile1;
51-
52-
BufferedReader in = new BufferedReader(new FileReader(dotFile));
53-
54-
String line;
51+
for ( Object dotFile1 : dotFiles )
52+
{
53+
File dotFile = (File) dotFile1;
5554

56-
while ((line = in.readLine()) != null) {
57-
String[] s = StringUtils.split(line, ":");
55+
in = new BufferedReader( new FileReader( dotFile ) );
5856

59-
if (s.length == 1) {
60-
File directory = new File(dotFileDirectory, s[0]);
57+
for ( String line = in.readLine(); line != null; line = in.readLine() )
58+
{
59+
String[] s = StringUtils.split( line, ":" );
6160

62-
System.out.println("adding directory = " + directory);
61+
if ( s.length == 1 )
62+
{
63+
File directory = new File( dotFileDirectory, s[0] );
6364

64-
archiver.addDirectory(directory);
65-
} else {
66-
File directory = new File(dotFileDirectory, s[0]);
65+
System.out.println( "adding directory = " + directory );
6766

68-
System.out.println("adding directory = " + directory + " to: " + s[1]);
67+
archiver.addDirectory( directory );
68+
}
69+
else
70+
{
71+
File directory = new File( dotFileDirectory, s[0] );
6972

70-
if (s[1].endsWith("/")) {
71-
archiver.addDirectory(directory, s[1]);
72-
} else {
73-
archiver.addDirectory(directory, s[1] + "/");
74-
}
75-
}
76-
}
73+
System.out.println( "adding directory = " + directory + " to: " + s[1] );
7774

78-
in.close();
79-
}
75+
if ( s[1].endsWith( "/" ) )
76+
{
77+
archiver.addDirectory( directory, s[1] );
78+
}
79+
else
80+
{
81+
archiver.addDirectory( directory, s[1] + "/" );
82+
}
83+
}
84+
}
8085

86+
in.close();
87+
in = null;
88+
}
8189
}
8290
catch ( IOException e )
8391
{
8492
throw new ArchiverException( "Error processing dot files.", e );
8593
}
94+
finally
95+
{
96+
IOUtil.close( in );
97+
}
8698
}
8799

88100
public List getVirtualFiles()
89101
{
90102
return Collections.EMPTY_LIST;
91103
}
104+
92105
}

src/main/java/org/codehaus/plexus/archiver/tar/GZipTarFile.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ public GZipTarFile( File file )
2525
protected InputStream getInputStream( File file )
2626
throws IOException
2727
{
28-
final InputStream inputStream = super.getInputStream( file );
29-
return Streams.bufferedInputStream( new GZIPInputStream( inputStream )
30-
{
31-
public void close()
32-
throws IOException
33-
{
34-
super.close();
35-
inputStream.close();
36-
}
37-
} );
28+
return Streams.bufferedInputStream( new GZIPInputStream( super.getInputStream( file ) ) );
3829
}
3930
}

src/main/java/org/codehaus/plexus/archiver/util/FilterSupport.java

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/**
1313
* @deprecated Use {@link FileSelector} and {@link Archiver#addFileSet}.
1414
*/
15+
@Deprecated
1516
public class FilterSupport
1617
{
1718

src/main/java/org/codehaus/plexus/archiver/util/Streams.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,18 @@ public class Streams
3535

3636
public static BufferedInputStream bufferedInputStream( InputStream is )
3737
{
38-
return new BufferedInputStream( is, 65536 );
38+
return is instanceof BufferedInputStream
39+
? (BufferedInputStream) is
40+
: new BufferedInputStream( is, 65536 );
41+
3942
}
4043

4144
public static BufferedOutputStream bufferedOutputStream( OutputStream os )
4245
{
43-
return new BufferedOutputStream( os, 65536 );
46+
return os instanceof BufferedOutputStream
47+
? (BufferedOutputStream) os
48+
: new BufferedOutputStream( os, 65536 );
49+
4450
}
4551

4652
public static byte[] cacheBuffer()

0 commit comments

Comments
 (0)