1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
/* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
*
* This program and the accompanying materials are made available under
* the terms of the Common Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/cpl-v10.html
*
* $Id: UDataInputStream.java,v 1.1.1.1.2.1 2004/07/10 03:34:53 vlad_r Exp $
*/
package com.vladium.jcd.lib;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
// ----------------------------------------------------------------------------
/**
* A trivial extension to java.io.DataInputStream to provide methods for
* reading unsigned 16- and 32-bit integers with simple mnemonics. It uses
* correspondingly wider native types to preserve the full range of the unsigned
* types.
*
* @author (C) 2001, Vlad Roubtsov
*/
public
final class UDataInputStream extends DataInputStream
{
// public: ................................................................
public UDataInputStream (final InputStream _in)
{
super (_in);
}
public final int readU2 () throws IOException
{
final short value = readShort ();
return ((int) value) & 0xFFFF; // widening cast sign-extends
}
public final long readU4 () throws IOException
{
final int value = readInt ();
return ((long) value) & 0xFFFFFFFFL; // widening cast sign-extends
}
// protected: .............................................................
// package: ...............................................................
// private: ...............................................................
} // end of class
// ----------------------------------------------------------------------------
|