You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by co...@apache.org on 2017/04/25 13:46:37 UTC
svn commit: r1792611 - in /directory/apacheds/trunk:
http-integration/src/main/java/org/apache/directory/server/integration/http/
installers-maven-plugin/src/main/java/org/apache/directory/server/installers/
interceptors/changelog/src/main/java/org/apa...
Author: coheigea
Date: Tue Apr 25 13:46:37 2017
New Revision: 1792611
URL: http://svn.apache.org/viewvc?rev=1792611&view=rev
Log:
Switching FileInput/OutputStream to Files.newInput/OutputStream
- See https://www.cloudbees.com/blog/fileinputstream-fileoutputstream-considered-harmful
Modified:
directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/HttpServer.java
directory/apacheds/trunk/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/MojoHelperUtils.java
directory/apacheds/trunk/interceptors/changelog/src/main/java/org/apache/directory/server/core/changelog/MemoryChangeLogStore.java
directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/DefaultJournalStore.java
directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaLdifToPartitionExtractor.java
directory/apacheds/trunk/kerberos-client/src/main/java/org/apache/directory/kerberos/credentials/cache/CredentialsCache.java
directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/Keytab.java
directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
directory/apacheds/trunk/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java
directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/LdifConfigExtractor.java
Modified: directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/HttpServer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/HttpServer.java?rev=1792611&r1=1792610&r2=1792611&view=diff
==============================================================================
--- directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/HttpServer.java (original)
+++ directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/HttpServer.java Tue Apr 25 13:46:37 2017
@@ -23,10 +23,11 @@ package org.apache.directory.server.inte
import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.FilenameFilter;
+import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.cert.Certificate;
@@ -55,7 +56,8 @@ import org.eclipse.jetty.server.handler.
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.webapp.WebAppContext;
-import org.eclipse.jetty.xml.XmlConfiguration;import org.slf4j.Logger;
+import org.eclipse.jetty.xml.XmlConfiguration;
+import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -114,7 +116,8 @@ public class HttpServer
if ( confFile != null )
{
- jettyConf = new XmlConfiguration( new FileInputStream( confFile ) );
+ InputStream input = Files.newInputStream( Paths.get( confFile ) );
+ jettyConf = new XmlConfiguration( input );
LOG.info( "configuring jetty http server from the configuration file {}", confFile );
@@ -205,7 +208,7 @@ public class HttpServer
ks.setKeyEntry( "privatekey", keyPair.getPrivate(), password.toCharArray(), new Certificate[]
{ cert } );
- try ( OutputStream stream = new FileOutputStream( ksFile ) )
+ try ( OutputStream stream = Files.newOutputStream( ksFile.toPath() ) )
{
ks.store( stream, password.toCharArray() );
}
Modified: directory/apacheds/trunk/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/MojoHelperUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/MojoHelperUtils.java?rev=1792611&r1=1792610&r2=1792611&view=diff
==============================================================================
--- directory/apacheds/trunk/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/MojoHelperUtils.java (original)
+++ directory/apacheds/trunk/installers-maven-plugin/src/main/java/org/apache/directory/server/installers/MojoHelperUtils.java Tue Apr 25 13:46:37 2017
@@ -22,14 +22,14 @@ package org.apache.directory.server.inst
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
+import java.nio.file.Files;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
@@ -63,7 +63,7 @@ public final class MojoHelperUtils
{
mojo.getLog().info( "Copying " + fileName + " to " + to );
- try ( FileOutputStream out = new FileOutputStream( to ) )
+ try ( OutputStream out = Files.newOutputStream( to.toPath() ) )
{
IOUtil.copy( from, out );
}
@@ -79,7 +79,8 @@ public final class MojoHelperUtils
{
// buffer so it isn't reading a byte at a time!
try ( Reader fileReader = new BufferedReader( new InputStreamReader( from ) );
- Writer fileWriter = new OutputStreamWriter( new FileOutputStream( to ) ) )
+ OutputStream out = Files.newOutputStream( to.toPath() );
+ Writer fileWriter = new OutputStreamWriter( out ) )
{
Reader reader = null;
if ( filtering )
@@ -111,7 +112,8 @@ public final class MojoHelperUtils
public static void copyAsciiFile( GenerateMojo mymojo, Properties filterProperties, File from, File to,
boolean filtering ) throws IOException
{
- copyAsciiFile( mymojo, filterProperties, from.getAbsolutePath(), new FileInputStream( from ), to, filtering );
+ InputStream input = Files.newInputStream( from.toPath() );
+ copyAsciiFile( mymojo, filterProperties, from.getAbsolutePath(), input, to, filtering );
}
Modified: directory/apacheds/trunk/interceptors/changelog/src/main/java/org/apache/directory/server/core/changelog/MemoryChangeLogStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/changelog/src/main/java/org/apache/directory/server/core/changelog/MemoryChangeLogStore.java?rev=1792611&r1=1792610&r2=1792611&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/changelog/src/main/java/org/apache/directory/server/core/changelog/MemoryChangeLogStore.java (original)
+++ directory/apacheds/trunk/interceptors/changelog/src/main/java/org/apache/directory/server/core/changelog/MemoryChangeLogStore.java Tue Apr 25 13:46:37 2017
@@ -21,14 +21,15 @@ package org.apache.directory.server.core
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
+import java.io.InputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.OutputStream;
import java.io.PrintWriter;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -209,11 +210,11 @@ public class MemoryChangeLogStore implem
}
}
- FileOutputStream out = null;
+ OutputStream out = null;
try
{
- out = new FileOutputStream( tagFile );
+ out = Files.newOutputStream( tagFile.toPath() );
Properties props = new Properties();
@@ -264,11 +265,11 @@ public class MemoryChangeLogStore implem
if ( revFile.exists() )
{
Properties props = new Properties();
- FileInputStream in = null;
+ InputStream in = null;
try
{
- in = new FileInputStream( revFile );
+ in = Files.newInputStream( revFile.toPath() );
props.load( in );
ArrayList<Long> revList = new ArrayList<Long>();
@@ -336,7 +337,7 @@ public class MemoryChangeLogStore implem
try
{
- in = new ObjectInputStream( new FileInputStream( file ) );
+ in = new ObjectInputStream( Files.newInputStream( file.toPath() ) );
int size = in.readInt();
ArrayList<ChangeLogEvent> changeLogEvents = new ArrayList<ChangeLogEvent>( size );
@@ -402,7 +403,7 @@ public class MemoryChangeLogStore implem
try
{
- out = new ObjectOutputStream( new FileOutputStream( file ) );
+ out = new ObjectOutputStream( Files.newOutputStream( file.toPath() ) );
out.writeInt( events.size() );
Modified: directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/DefaultJournalStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/DefaultJournalStore.java?rev=1792611&r1=1792610&r2=1792611&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/DefaultJournalStore.java (original)
+++ directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/DefaultJournalStore.java Tue Apr 25 13:46:37 2017
@@ -21,11 +21,12 @@ package org.apache.directory.server.core
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
+import java.nio.file.Files;
+import java.nio.file.StandardOpenOption;
import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.ldif.LdifEntry;
@@ -87,7 +88,7 @@ public class DefaultJournalStore impleme
// The new requests are added at the end of the existing journal
writer = new PrintWriter(
new OutputStreamWriter(
- new FileOutputStream( journal, true ) ) );
+ Files.newOutputStream( journal.toPath(), StandardOpenOption.APPEND ) ) );
}
Modified: directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaLdifToPartitionExtractor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaLdifToPartitionExtractor.java?rev=1792611&r1=1792610&r2=1792611&view=diff
==============================================================================
--- directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaLdifToPartitionExtractor.java (original)
+++ directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaLdifToPartitionExtractor.java Tue Apr 25 13:46:37 2017
@@ -21,11 +21,11 @@ package org.apache.directory.server.core
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InvalidObjectException;
+import java.nio.file.Files;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
@@ -174,7 +174,7 @@ public class SchemaLdifToPartitionExtrac
throw new FileNotFoundException( I18n.err( I18n.ERR_08002, source.getAbsolutePath() ) );
}
- FileInputStream in = new FileInputStream( source );
+ InputStream in = Files.newInputStream( source.toPath() );
addFromStream( in, source.getAbsolutePath() );
}
Modified: directory/apacheds/trunk/kerberos-client/src/main/java/org/apache/directory/kerberos/credentials/cache/CredentialsCache.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-client/src/main/java/org/apache/directory/kerberos/credentials/cache/CredentialsCache.java?rev=1792611&r1=1792610&r2=1792611&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-client/src/main/java/org/apache/directory/kerberos/credentials/cache/CredentialsCache.java (original)
+++ directory/apacheds/trunk/kerberos-client/src/main/java/org/apache/directory/kerberos/credentials/cache/CredentialsCache.java Tue Apr 25 13:46:37 2017
@@ -21,11 +21,10 @@ package org.apache.directory.kerberos.cr
import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
@@ -45,7 +44,7 @@ public class CredentialsCache
public static CredentialsCache load( File cacheFile ) throws IOException
{
- return load(new FileInputStream( cacheFile ));
+ return load(Files.newInputStream( cacheFile.toPath() ));
}
public static CredentialsCache load( InputStream is ) throws IOException
@@ -60,7 +59,7 @@ public class CredentialsCache
public static void store( File fileName, CredentialsCache credCache ) throws IOException
{
- store( new FileOutputStream(fileName), credCache );
+ store( Files.newOutputStream( fileName.toPath() ), credCache );
}
public static void store( OutputStream os, CredentialsCache credCache ) throws IOException
Modified: directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/Keytab.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/Keytab.java?rev=1792611&r1=1792610&r2=1792611&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/Keytab.java (original)
+++ directory/apacheds/trunk/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/keytab/Keytab.java Tue Apr 25 13:46:37 2017
@@ -21,12 +21,13 @@ package org.apache.directory.server.kerb
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
+import java.nio.channels.Channels;
+import java.nio.channels.WritableByteChannel;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -224,7 +225,7 @@ public class Keytab
*/
protected static byte[] getBytesFromFile( File file ) throws IOException
{
- try (InputStream is = new FileInputStream( file ))
+ try (InputStream is = Files.newInputStream( file.toPath() ))
{
long length = file.length();
@@ -267,16 +268,16 @@ public class Keytab
protected void writeFile( ByteBuffer buffer, File file ) throws IOException
{
// Set append false to replace existing.
- FileOutputStream fout = new FileOutputStream( file, false );
+ OutputStream out = Files.newOutputStream( file.toPath() );
- try (FileChannel wChannel = fout.getChannel())
+ try (WritableByteChannel channel = Channels.newChannel( out ))
{
// Write the bytes between the position and limit.
- wChannel.write( buffer );
+ channel.write( buffer );
}
finally
{
- fout.close();
+ out.close();
}
}
}
Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java?rev=1792611&r1=1792610&r2=1792611&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapServer.java Tue Apr 25 13:46:37 2017
@@ -20,8 +20,10 @@
package org.apache.directory.server.ldap;
-import java.io.FileInputStream;
+import java.io.InputStream;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.security.KeyStore;
import java.security.Provider;
import java.security.Security;
@@ -380,9 +382,9 @@ public class LdapServer extends Director
else
{
keyStore = KeyStore.getInstance( KeyStore.getDefaultType() );
- try ( FileInputStream fis = new FileInputStream( keystoreFile ) )
+ try ( InputStream is = Files.newInputStream( Paths.get( keystoreFile ) ) )
{
- keyStore.load( fis, null );
+ keyStore.load( is, null );
}
}
Modified: directory/apacheds/trunk/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java?rev=1792611&r1=1792610&r2=1792611&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java (original)
+++ directory/apacheds/trunk/protocol-shared/src/main/java/org/apache/directory/server/protocol/shared/store/LdifFileLoader.java Tue Apr 25 13:46:37 2017
@@ -21,9 +21,10 @@ package org.apache.directory.server.prot
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.Files;
import java.util.Collections;
import java.util.List;
@@ -264,11 +265,11 @@ public class LdifFileLoader
* @return the input stream to the ldif file.
* @throws FileNotFoundException if the file cannot be found.
*/
- private InputStream getLdifStream() throws FileNotFoundException
+ private InputStream getLdifStream() throws FileNotFoundException, IOException
{
if ( ldif.exists() )
{
- return new FileInputStream( ldif );
+ return Files.newInputStream( ldif.toPath() );
}
else
{
Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/LdifConfigExtractor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/LdifConfigExtractor.java?rev=1792611&r1=1792610&r2=1792611&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/LdifConfigExtractor.java (original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/LdifConfigExtractor.java Tue Apr 25 13:46:37 2017
@@ -24,12 +24,13 @@ package org.apache.directory.server.conf
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.net.URL;
+import java.nio.file.Files;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Stack;
@@ -192,7 +193,7 @@ public final class LdifConfigExtractor
}
}
- try ( FileOutputStream out = new FileOutputStream( destination ) )
+ try ( OutputStream out = Files.newOutputStream( destination.toPath() ) )
{
while ( in.available() > 0 )
{
Re: svn commit: r1792611 - in /directory/apacheds/trunk:
http-integration/src/main/java/org/apache/directory/server/integration/http/
installers-maven-plugin/src/main/java/org/apache/directory/server/installers/ interceptors/changelog/src/main/java/org/apa...
Posted by Colm O hEigeartaigh <co...@apache.org>.
Hi Emmanuel,
Yes we should convert them, so long as all of the projects use Java 7!
Please go ahead and convert them if you want to :-)
Colm.
On Tue, Apr 25, 2017 at 4:10 PM, Emmanuel Lécharny <el...@gmail.com>
wrote:
> Hi Colm,
>
> I do agree that the change is valid and useful.
>
> Now, there are many references to FileOutputStream and FileInutStream in :
> - api-ldap_client-api
> - api-ldap-schema-data
> - api-util
> - mavibot
> - api-dsml-parser
> - api-ldap-model
> - api-ldap-schema-converter
>
> I guess we should also convert those guys ? May be you are already
> working on it ? Please let me know, otherwise I'll clean those guys tonite.
>
>
> Thanks !
>
> --
> Emmanuel Lecharny
>
> Symas.com
> directory.apache.org
>
>
--
Colm O hEigeartaigh
Talend Community Coder
http://coders.talend.com
Re: svn commit: r1792611 - in /directory/apacheds/trunk:
http-integration/src/main/java/org/apache/directory/server/integration/http/
installers-maven-plugin/src/main/java/org/apache/directory/server/installers/
interceptors/changelog/src/main/java/org/apa...
Posted by Emmanuel Lécharny <el...@gmail.com>.
Hi Colm,
I do agree that the change is valid and useful.
Now, there are many references to FileOutputStream and FileInutStream in :
- api-ldap_client-api
- api-ldap-schema-data
- api-util
- mavibot
- api-dsml-parser
- api-ldap-model
- api-ldap-schema-converter
I guess we should also convert those guys ? May be you are already
working on it ? Please let me know, otherwise I'll clean those guys tonite.
Thanks !
--
Emmanuel Lecharny
Symas.com
directory.apache.org