You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2009/05/27 23:44:47 UTC
svn commit: r779325 -
/directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/HexDialog.java
Author: seelmann
Date: Wed May 27 21:44:46 2009
New Revision: 779325
URL: http://svn.apache.org/viewvc?rev=779325&view=rev
Log:
Simplified file I/O by using FileUtils
Modified:
directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/HexDialog.java
Modified: directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/HexDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/HexDialog.java?rev=779325&r1=779324&r2=779325&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/HexDialog.java (original)
+++ directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/HexDialog.java Wed May 27 21:44:46 2009
@@ -21,13 +21,10 @@
package org.apache.directory.studio.ldapbrowser.common.dialogs;
-import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
+import org.apache.commons.io.FileUtils;
import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
@@ -108,22 +105,13 @@
try
{
File file = new File( returnedFileName );
- FileOutputStream out = new FileOutputStream( file );
- out.write( currentData );
- out.flush();
- out.close();
- }
- catch ( FileNotFoundException e )
- {
- ConnectionUIPlugin.getDefault().getExceptionHandler().handleException(
- new Status( IStatus.ERROR, BrowserCommonConstants.PLUGIN_ID, IStatus.ERROR,
- Messages.getString("HexDialog.CantWriteToFile"), e ) ); //$NON-NLS-1$
+ FileUtils.writeByteArrayToFile( file, currentData );
}
catch ( IOException e )
{
ConnectionUIPlugin.getDefault().getExceptionHandler().handleException(
- new Status( IStatus.ERROR, BrowserCommonConstants.PLUGIN_ID, IStatus.ERROR,
- Messages.getString("HexDialog.CantWriteToFile"), e ) ); //$NON-NLS-1$
+ new Status( IStatus.ERROR, BrowserCommonConstants.PLUGIN_ID, IStatus.ERROR, Messages
+ .getString( "HexDialog.CantWriteToFile" ), e ) ); //$NON-NLS-1$
}
}
}
@@ -137,30 +125,14 @@
try
{
File file = new File( returnedFileName );
- FileInputStream in = new FileInputStream( file );
- ByteArrayOutputStream out = new ByteArrayOutputStream( ( int ) file.length() );
- byte[] buf = new byte[4096];
- int len;
- while ( ( len = in.read( buf ) ) > 0 )
- {
- out.write( buf, 0, len );
- }
- currentData = out.toByteArray();
+ currentData = FileUtils.readFileToByteArray( file );
hexText.setText( toFormattedHex( currentData ) );
- out.close();
- in.close();
- }
- catch ( FileNotFoundException e )
- {
- ConnectionUIPlugin.getDefault().getExceptionHandler().handleException(
- new Status( IStatus.ERROR, BrowserCommonConstants.PLUGIN_ID, IStatus.ERROR, Messages.getString("HexDialog.CantReadFile"), //$NON-NLS-1$
- e ) );
}
catch ( IOException e )
{
ConnectionUIPlugin.getDefault().getExceptionHandler().handleException(
- new Status( IStatus.ERROR, BrowserCommonConstants.PLUGIN_ID, IStatus.ERROR, Messages.getString("HexDialog.CantReadFile"), //$NON-NLS-1$
- e ) );
+ new Status( IStatus.ERROR, BrowserCommonConstants.PLUGIN_ID, IStatus.ERROR, Messages
+ .getString( "HexDialog.CantReadFile" ), e ) ); //$NON-NLS-1$
}
}
}