⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 size.java

📁 使用方法: 实例程序的运行: 每个实例下都有本实例的.xml文件或.html文件或.xsl文件
💻 JAVA
字号:
/*
    Copyright (c) 1999 Bruce Martin, a contributor to the Xbean project.
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to
    deal in the Software without restriction, including without limitation the
    rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    sell copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

        The above copyright notice and this permission notice shall be included
        in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    DEALINGS IN THE SOFTWARE.
*/


// A simple utility bean that records the size of the serialized form of the
// document passed to it.

package org.xbeans.utilities;

import org.xbeans.*;
import org.w3c.dom.Document;
import java.io.*;

public class size implements DOMListener, DOMSource {

    public size() {
    }

    // DomListener method
    // Simply uses the Java serialization mechanism to create a byte array
    // for the incoming document and record the size of it in bytes.
    public void documentReady(DOMEvent evt) throws XbeansException {
        try {
            ByteArrayOutputStream bastream = new ByteArrayOutputStream();
            ObjectOutputStream p = new ObjectOutputStream(bastream);
            p.writeObject(evt.getDocument());
            p.flush();
            size = bastream.size();
        } catch (Throwable e) {
            throw new XbeansException(
                        "",
                        "size",
                        "error calculating size of document "+e,
                        "error calculating size of document "+e
                        );
        }
        if (DOMListener==null) return;
        DOMListener.documentReady(evt);
    }

    public int getSize() {
        return size;
    }

    /** Sets the target listener for the DOM events. */
    public void setDOMListener(DOMListener newDomListener) {
        DOMListener = newDomListener;
    }

    /** Returns the target listener for the DOM events. */
    public DOMListener getDOMListener(){
        return DOMListener;
    }
    
    private int size;
    private DOMListener DOMListener;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -