本文整理匯總了Java中java.beans.XMLDecoder.setExceptionListener方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLDecoder.setExceptionListener方法的具體用法?Java XMLDecoder.setExceptionListener怎麽用?Java XMLDecoder.setExceptionListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.beans.XMLDecoder
的用法示例。
在下文中一共展示了XMLDecoder.setExceptionListener方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import java.beans.XMLDecoder; //導入方法依賴的package包/類
/**
* This is entry point to start testing.
*
* @param security use {@code true} to start
* second pass in secure context
*/
final void test(boolean security) {
byte[] array = getFieldValue("XML").getBytes(); // NON-NLS: the field name
ByteArrayInputStream input = new ByteArrayInputStream(array);
XMLDecoder decoder = new XMLDecoder(input);
decoder.setExceptionListener(this);
validate(decoder);
try {
throw new Error("unexpected object" + decoder.readObject());
} catch (ArrayIndexOutOfBoundsException exception) {
// expected exception
}
decoder.close();
if (security) {
System.setSecurityManager(new SecurityManager());
test(false);
}
}
示例2: readObject
import java.beans.XMLDecoder; //導入方法依賴的package包/類
private Object readObject(byte[] array) {
ByteArrayInputStream input = new ByteArrayInputStream(array);
XMLDecoder decoder = new XMLDecoder(input);
decoder.setExceptionListener(this);
initialize(decoder);
Object object = decoder.readObject();
decoder.close();
return object;
}
示例3: loadLocal
import java.beans.XMLDecoder; //導入方法依賴的package包/類
public Object loadLocal() throws FileNotFoundException {
Window frame = getFrame();
// Choose the file to load.
JFileChooser fileChooser = new JFileChooser( _directoryName );
fileChooser.setDialogTitle( "Load File" );
int rval = fileChooser.showOpenDialog( frame );
_directoryName = fileChooser.getCurrentDirectory().getAbsolutePath();
File selectedFile = fileChooser.getSelectedFile();
if( rval == JFileChooser.CANCEL_OPTION || selectedFile == null ) {
return null;
}
// XML decode directly from the file.
Object object = null;
String filename = selectedFile.getAbsolutePath();
FileInputStream fis = new FileInputStream( filename );
BufferedInputStream bis = new BufferedInputStream( fis );
XMLDecoder decoder = new XMLDecoder( bis );
decoder.setExceptionListener( new ExceptionListener() {
private int errors = 0;
// Report the first recoverable exception.
public void exceptionThrown( Exception e ) {
if( errors == 0 ) {
showError( QWIResources.getString( "Load.error.decode" ), e );
errors++;
}
}
} );
object = decoder.readObject();
decoder.close();
return object;
}
示例4: loadJNLP
import java.beans.XMLDecoder; //導入方法依賴的package包/類
private Object loadJNLP() throws UnavailableServiceException, IOException {
Window frame = getFrame();
// Get the JNLP service for opening files.
FileOpenService fos = (FileOpenService)ServiceManager.lookup( "javax.jnlp.FileOpenService" );
if( fos == null ) {
throw new UnavailableServiceException( "JNLP FileOpenService is unavailable" );
}
// Read the configuration from a file.
FileContents fc = fos.openFileDialog( _directoryName, null );
if( fc == null ) {
return null;
}
_directoryName = getDirectoryName( fc.getName() );
// Convert the FileContents to an input stream.
InputStream inputStream = fc.getInputStream();
// XML-decode the input stream.
Object object = null;
XMLDecoder decoder = new XMLDecoder( inputStream );
decoder.setExceptionListener( new ExceptionListener() {
private int errors = 0;
// Report the first recoverable exception.
public void exceptionThrown( Exception e ) {
if( errors == 0 ) {
showError( QWIResources.getString( "Load.error.decode" ), e );
errors++;
}
}
} );
object = decoder.readObject();
decoder.close();
return object;
}