Skip to content

Commit d474745

Browse files
committed
#38: Downgrade PrintWriter to Writer in Manifest
This closes #38
1 parent 75945aa commit d474745

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

Diff for: src/main/java/org/codehaus/plexus/archiver/jar/Manifest.java

+12-11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.PrintWriter;
2525
import java.io.Reader;
2626
import java.io.StringWriter;
27+
import java.io.Writer;
2728
import java.util.ArrayList;
2829
import java.util.Collection;
2930
import java.util.Enumeration;
@@ -299,12 +300,12 @@ public void addValue( String value )
299300
}
300301

301302
/**
302-
* Write the attribute out to a print writer.
303+
* Writes the attribute out to a writer.
303304
*
304305
* @param writer the Writer to which the attribute is written
305306
* @throws IOException if the attribute value cannot be written
306307
*/
307-
void write( PrintWriter writer )
308+
void write( Writer writer )
308309
throws IOException
309310
{
310311
StringWriter sWriter = new StringWriter();
@@ -317,7 +318,7 @@ void write( PrintWriter writer )
317318

318319
byte[] convertedToUtf8 = sWriter.toString().getBytes( "UTF-8" );
319320

320-
writer.print( new String( convertedToUtf8, "UTF-8" ) );
321+
writer.write( new String( convertedToUtf8, "UTF-8" ) );
321322
}
322323

323324
/**
@@ -327,7 +328,7 @@ void write( PrintWriter writer )
327328
* @param value the attribute value
328329
* @throws IOException if the attribute value cannot be written
329330
*/
330-
private void writeValue( PrintWriter writer, String value )
331+
private void writeValue( Writer writer, String value )
331332
throws IOException
332333
{
333334
String nameValue = name + ": " + value;
@@ -350,7 +351,7 @@ private void writeValue( PrintWriter writer, String value )
350351
* @param line the manifest line to be written
351352
* @throws java.io.IOException when Io excepts
352353
*/
353-
private void writeLine( PrintWriter writer, String line )
354+
private void writeLine( Writer writer, String line )
354355
throws IOException
355356
{
356357
while ( line.getBytes().length > MAX_LINE_LENGTH )
@@ -367,10 +368,10 @@ private void writeLine( PrintWriter writer, String line )
367368
{
368369
throw new IOException( "Unable to write manifest line " + line );
369370
}
370-
writer.print( section + EOL );
371+
writer.write( section + EOL );
371372
line = " " + line.substring( breakIndex );
372373
}
373-
writer.print( line + EOL );
374+
writer.write( line + EOL );
374375
}
375376
}
376377

@@ -417,7 +418,7 @@ public void addValue( String value )
417418
setValue( value1 );
418419
}
419420

420-
void write( PrintWriter writer )
421+
void write( Writer writer )
421422
throws IOException
422423
{
423424
throw new UnsupportedOperationException( "Cant do this" );
@@ -845,12 +846,12 @@ public void addConfiguredAttribute( Attribute attribute )
845846
}
846847

847848
/**
848-
* Write the manifest out to a print writer.
849+
* Writes the manifest out to a writer.
849850
*
850851
* @param writer the Writer to which the manifest is written
851852
* @throws IOException if the manifest cannot be written
852853
*/
853-
public void write( PrintWriter writer )
854+
public void write( Writer writer )
854855
throws IOException
855856
{
856857
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
@@ -872,7 +873,7 @@ public String toString()
872873
StringWriter sw = new StringWriter();
873874
try
874875
{
875-
write( new PrintWriter( sw ) );
876+
write( sw );
876877
}
877878
catch ( IOException e )
878879
{

Diff for: src/test/java/org/codehaus/plexus/archiver/jar/ManifestTest.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.io.FileInputStream;
2121
import java.io.IOException;
2222
import java.io.InputStream;
23-
import java.io.PrintWriter;
2423
import java.io.StringWriter;
2524
import java.util.jar.Attributes;
2625
import org.codehaus.plexus.PlexusTestCase;
@@ -100,7 +99,7 @@ public void testAttributeLongLineWrite()
10099
+ "123456789 123456789 123456789 ";
101100
attr.setName( "test" );
102101
attr.setValue( longLineOfChars );
103-
attr.write( new PrintWriter( writer ) );
102+
attr.write( writer );
104103
writer.flush();
105104
assertEquals( "should be multiline",
106105
"test: 123456789 123456789 123456789 123456789 123456789 123456789 1234"
@@ -168,7 +167,7 @@ public void testAttributeSerialization()
168167
manifest.getEntries().put( "sub", attributes );
169168
manifest.getSection( "sub" ).addAttributeAndCheck( new Manifest.Attribute( "attB", "caB" ) );
170169
StringWriter writer = new StringWriter();
171-
manifest.write( new PrintWriter( writer ) );
170+
manifest.write( writer );
172171
String s = writer.toString();
173172
assertTrue( s.contains( "mfa1: fud1" ) );
174173
assertTrue( s.contains( "mfa2: fud2" ) );
@@ -207,7 +206,7 @@ public void checkMultiLineAttribute( String in, String expected )
207206
Manifest.Attribute attr = new Manifest.Attribute();
208207
attr.setName( "test" );
209208
attr.setValue( in );
210-
attr.write( new PrintWriter( writer ) );
209+
attr.write( writer );
211210
writer.flush();
212211

213212
// Print the string with whitespace replaced with special codes
@@ -280,7 +279,7 @@ public void testAttributeSerializationPlexusManifest()
280279
attributes.addConfiguredAttribute( new Manifest.Attribute( "attB", "caB" ) );
281280
manifest.addConfiguredSection( attributes );
282281
StringWriter writer = new StringWriter();
283-
manifest.write( new PrintWriter( writer ) );
282+
manifest.write( writer );
284283
String s = writer.toString();
285284
assertTrue( s.contains( "mfa1: fud1" ) );
286285
assertTrue( s.contains( "mfa2: fud2" ) );

0 commit comments

Comments
 (0)