📄 resourceinputstream.java
字号:
/* * @(#)ResourceInputStream.java 1.6 01/08/21 * Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved. * * This software is the confidential and proprietary information of Sun * Microsystems, Inc. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Sun. * * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. */package com.sun.midp.io;import java.io.*;import java.util.*;/** * Input stream class for accessing resource files in classpath. */public class ResourceInputStream extends InputStream { /** * instance handle to hold the native reference to the * underlying stream. * This field must be an Object, since it will point to something * that needs to be protected from the garbage collector. */ private Object handle; /** * Construct a resource input stream for accessing objects in the jar file. * * @param name the name of the resource in classpath to access. * @exception IOException if an I/O error occurs. */ public ResourceInputStream(String name) throws IOException { if (handle != null) { throw new IOException(); } handle = open(name); } /** * Reads the next byte of data from the input stream. * * @return the next byte of data, or <code>-1</code> if the end of the * stream is reached. * @exception IOException if an I/O error occurs. */ public int read() throws IOException { return read(handle); } /** * closes the open resource stream. * @exception IOException if an I/O error occurs. */ public void close() throws IOException { close(handle); handle = null; } /** * native interface to open resource as stream. * @param name name of the resource in CLASSPATH * @return the Object reference to the located resource. * @exception IOException if I/O error occurs. */ private static native Object open(String name) throws IOException; /** * native interface to read a byte from the opened resource. * @param handle for the opened resource * @return a character read from the opened resource. * @exception IOException if I/O error occurs. */ private static native int read(Object handle) throws IOException; /** * native interface to close the opened resource. * @param handle for the opened resource * @exception IOException if I/O error occurs. */ private static native void close(Object handle) throws IOException;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -