當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLDecoder.setExceptionListener方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:AbstractTest.java

示例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;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:10,代碼來源:AbstractTest.java

示例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;
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:36,代碼來源:PersistenceManager.java

示例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;
    }
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:40,代碼來源:PersistenceManager.java


注:本文中的java.beans.XMLDecoder.setExceptionListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。