Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSHADE-360] avoid PrintWriter #44

Merged
merged 3 commits into from
Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand Down Expand Up @@ -211,16 +210,15 @@ public void modifyOutputStream( JarOutputStream jos )
jarEntry.setTime( time );
jos.putNextEntry( jarEntry );

Writer pow;
Writer writer;
if ( StringUtils.isNotEmpty( encoding ) )
{
pow = new OutputStreamWriter( jos, encoding );
writer = new OutputStreamWriter( jos, encoding );
}
else
{
pow = new OutputStreamWriter( jos );
writer = new OutputStreamWriter( jos );
}
PrintWriter writer = new PrintWriter( pow );

int count = 0;
for ( String line : entries )
Expand All @@ -233,26 +231,26 @@ public void modifyOutputStream( JarOutputStream jos )

if ( count == 2 && copyright != null )
{
writer.print( copyright );
writer.print( '\n' );
writer.write( copyright );
writer.write( '\n' );
}
else
{
writer.print( line );
writer.print( '\n' );
writer.write( line );
writer.write( '\n' );
}
if ( count == 3 )
{
//do org stuff
for ( Map.Entry<String, Set<String>> entry : organizationEntries.entrySet() )
{
writer.print( entry.getKey() );
writer.print( '\n' );
writer.write( entry.getKey() );
writer.write( '\n' );
for ( String l : entry.getValue() )
{
writer.print( l );
writer.write( l );
}
writer.print( '\n' );
writer.write( '\n' );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStreamWriter;
import java.io.StringReader;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -136,15 +137,17 @@ public void modifyOutputStream( JarOutputStream jos )
jos.putNextEntry( jarEntry );


//read the content of service file for candidate classes for relocation
PrintWriter writer = new PrintWriter( jos );
// read the content of service file for candidate classes for relocation.
// Specification requires that this file is encoded in UTF-8.
Writer writer = new OutputStreamWriter( jos, StandardCharsets.UTF_8 );
InputStreamReader streamReader = new InputStreamReader( data.toInputStream() );
BufferedReader reader = new BufferedReader( streamReader );
String className;

while ( ( className = reader.readLine() ) != null )
{
writer.println( className );
writer.write( className );
writer.write( System.getProperty( "line.separator" ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.lineSeparator()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea. done.

writer.flush();
}

Expand Down