本文整理汇总了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;
}