📄 inputstorage.java
字号:
/* * @(#)InputStorage.java 1.3 01/08/10 * * Copyright (c) 2001 Sun Microsystems, Inc., 901 San Antonio Road, * Palo Alto, CA 94303, U.S.A. All Rights Reserved. * * Sun Microsystems, Inc. has intellectual property rights relating * to the technology embodied in this software. In particular, and * without limitation, these intellectual property rights may include * one or more U.S. patents, foreign patents, or pending * applications. Sun, Sun Microsystems, the Sun logo, Java, KJava, * and all Sun-based and Java-based marks are trademarks or * registered trademarks of Sun Microsystems, Inc. in the United * States and other countries. * * This software is distributed under licenses restricting its use, * copying, distribution, and decompilation. No part of this * software may be reproduced in any form by any means without prior * written authorization of Sun and its licensors, if any. * * FEDERAL ACQUISITIONS: Commercial Software -- Government Users * Subject to Standard License Terms and Conditions */package com.sun.midp.publickeystore;import java.io.*;/** * Retieves stored fields from an InputStream. * Since Java Microedition has no serialization, this is a simple substitute. */class InputStorage extends Storage { /** stream to read from */ private DataInputStream in; /** * Constructs an InputStorage for an InputStream. * @param input the input storage input stream. * @exception IOException if the storage version cannot be read */ InputStorage(InputStream input) throws IOException { in = new DataInputStream(input); // skip past the version number. in.readByte(); } /** * Reads a field that was stored as tag, type, value set. * @param tag byte array of one byte to hold the tag of the field that * was read * @return value of field that was stored, or null if there are no more * fields * @exception IOException if the input storage was corrupted */ Object readValue(byte[] tag) throws IOException { byte type; try { in.readFully(tag, 0, 1); } catch (EOFException e) { // this just means there are no more fields in storage return null; } type = in.readByte(); if (type == BINARY_TYPE) { int len; byte[] value; /* * must read the length first, because DataOutputStream does not * handle handle byte arrays. */ len = in.readUnsignedShort(); if (len < 0) { throw new IOException("input storage corrupted"); } value = new byte[len]; in.readFully(value); return value; } if (type == STRING_TYPE) { return in.readUTF(); } if (type == LONG_TYPE) { return new Long(in.readLong()); } throw new IOException("input storage corrupted"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -