//
// ByteSwappedRandomAccessFile class
// part of the set of documents known as Java no sugar.
// Copyright (c) 1996 Sunil Gupta, sunil@magnetic.demon.co.uk
// placed into the public domain by the author
//
// integers and shorts work, but floats are buggered
// java doesnt come with byteswapping code, wot a crying shame.
//
import java.io.*;
import EncapsulatedRandomAccessFile
import ByteSwapper;
public class ByteSwappedRandomAccessFile extends EncapsulatedRandomAccessFile
{
public boolean byteSwapping = false;
//############################################################################
// Constructors
//############################################################################
public ByteSwappedRandomAccessFile(File file, String mode) throws IOException
{
super(file,mode);
}
//############################################################################
// these need to be byteswapped
//############################################################################
public short readShort() throws IOException
{
if (byteSwapping)
return ( ByteSwapper.swapShort(super.readShort()) );
else
return (super.readShort() );
}
public long readLong() throws IOException
{
if (byteSwapping)
return ( ByteSwapper.swapLong(super.readLong()) );
else
return (super.readLong() );
}
public int readInt() throws IOException
{
if (byteSwapping)
return( ByteSwapper.swapInt(super.readInt()) );
else
return (super.readInt());
}
public int readUnsignedShort() throws IOException
{
if (byteSwapping)
return ( ByteSwapper.swapShort( (short) super.readUnsignedShort()) );
else
return (super.readUnsignedShort() );
}
public double readDouble() throws IOException
{
//this is wrong but i dont quite know what to do
return super.readDouble();
}
public float readFloat() throws IOException
{
short mantissa,exponent;
double real_mantissa;
if (!byteSwapping)
return ( super.readFloat());
else
{
mantissa = readShort();
exponent = readShort();
real_mantissa = ((float)mantissa) / 32768.0; /* 32768.0 is: 2**15 */
return (float) ldexp(real_mantissa,exponent);
}
}
public static double ldexp(double x, int n)
{
double answer;
answer = x * Math.pow(2.0, n);
return answer;
}
}
| file: /Techref/language/java/nosugar/comms/code/ByteSwappedRandomAccessFile.java, 2KB, , updated: 1996/10/16 20:52, local time: 2012/5/25 08:23,
38.107.179.234:LOG IN |
| ©2012 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://www.piclist.com/techref/language/java/nosugar/comms/code/ByteSwappedRandomAccessFile.java"> language java nosugar comms code ByteSwappedRandomAccessFile</A> |
| Did you find what you needed? |
| piclist.com members can LOGIN to post questions, add public or private comments, links or even new pages(!). To start, fill out the form. |
|
Peter Todd has released source and sample projects for his artwork, including his 3d wireframe cube renderer for the PIC 18f6520 This includes examples of hardware developed with free software tools such as gEDA/gschem/PCB, SDCC, gputils and picp all on Linux. http://petertodd.ca/art/source-code/ |
.