rdf4j-postgis  Version 0.1.0.0
LEDataInputStream Class Reference

Little endian Data input stream. More...

Inheritance diagram for LEDataInputStream:
Collaboration diagram for LEDataInputStream:

Public Member Functions

 LEDataInputStream (final InputStream in)
 
long getPosition ()
 Get current stream position from the first written byte. More...
 
int available () throws IOException
 
final short readShort () throws IOException
 
short[] readShorts (int nbValues) throws IOException
 Read multiple values in one call. More...
 
final int readUnsignedShort () throws IOException
 
int[] readUnsignedShorts (int nbValues) throws IOException
 Read multiple values in one call. More...
 
final char readChar () throws IOException
 
final int readInt () throws IOException
 
int[] readInts (int nbValues) throws IOException
 Read multiple values in one call. More...
 
final long readLong () throws IOException
 
long[] readLongs (int nbValues) throws IOException
 Read multiple values in one call. More...
 
final float readFloat () throws IOException
 
float[] readFloats (int nbValues) throws IOException
 Read multiple values in one call. More...
 
final double readDouble () throws IOException
 
double[] readDoubles (int nbValues) throws IOException
 Read multiple values in one call. More...
 
final int read (byte b[], int off, int len) throws IOException
 
final void readFully (byte b[]) throws IOException
 
final void readFully (byte b[], int off, int len) throws IOException
 
final int skipBytes (int n) throws IOException
 
final void skipFully (int n) throws IOException
 
final boolean readBoolean () throws IOException
 
final byte readByte () throws IOException
 
int read () throws IOException
 
final int readUnsignedByte () throws IOException
 
final String readLine () throws IOException
 
final String readUTF () throws IOException
 
int realign (int blockSize) throws IOException
 Ralign stream position, skipping any remaining byte to match given block size. More...
 
final void close () throws IOException
 

Static Public Member Functions

static short readUnsignedByte (final byte[] buffer, final int offset)
 
static short readShort (final byte[] buffer, final int offset)
 
static int readUnsignedShort (final byte[] buffer, final int offset)
 
static char readChar (final byte[] buffer, final int offset)
 
static int readInt (final byte[] buffer, final int offset)
 
static long readUnsignedInt (final byte[] buffer, final int offset)
 
static long readLong (final byte[] buffer, final int offset)
 
static float readFloat (final byte[] buffer, final int offset)
 
static double readDouble (final byte[] buffer, final int offset)
 

Private Attributes

final DataInputStream ds
 
final InputStream in
 
final byte buffer [] = new byte[8]
 
long position = 0
 

Detailed Description

Little endian Data input stream.

Author
Johann Sorel (Geomatys)

Constructor & Destructor Documentation

◆ LEDataInputStream()

LEDataInputStream ( final InputStream  in)
37  {
38  this.in = in;
39  this.ds = new DataInputStream(in);
40  }
final DataInputStream ds
Definition: LEDataInputStream.java:32
final InputStream in
Definition: LEDataInputStream.java:33

References LEDataInputStream.in.

Member Function Documentation

◆ available()

int available ( ) throws IOException
51  {
52  return ds.available();
53  }

References LEDataInputStream.ds.

◆ close()

final void close ( ) throws IOException
289  {
290  ds.close();
291  }

References LEDataInputStream.ds.

◆ getPosition()

long getPosition ( )

Get current stream position from the first written byte.

Returns
stream position
46  {
47  return position;
48  }
long position
Definition: LEDataInputStream.java:35

References LEDataInputStream.position.

Referenced by LEDataInputStream.realign().

◆ read() [1/2]

int read ( ) throws IOException
247  {
248  position++;
249  return in.read();
250  }

References LEDataInputStream.in, and LEDataInputStream.position.

◆ read() [2/2]

final int read ( byte  b[],
int  off,
int  len 
) throws IOException
203  {
204  int nb = in.read(b, off, len);
205  position+=nb;
206  return nb;
207  }

References LEDataInputStream.in, and LEDataInputStream.position.

◆ readBoolean()

final boolean readBoolean ( ) throws IOException
235  {
236  position++;
237  return ds.readBoolean();
238  }

References LEDataInputStream.ds, and LEDataInputStream.position.

◆ readByte()

final byte readByte ( ) throws IOException
241  {
242  position++;
243  return ds.readByte();
244  }

References LEDataInputStream.ds, and LEDataInputStream.position.

◆ readChar() [1/2]

final char readChar ( ) throws IOException
101  {
102  position+=2;
103  ds.readFully(buffer, 0, 2);
104  return (char) ((buffer[1] & 0xff) << 8
105  | (buffer[0] & 0xff));
106  }
final byte buffer[]
Definition: LEDataInputStream.java:34

References LEDataInputStream.buffer, LEDataInputStream.ds, and LEDataInputStream.position.

◆ readChar() [2/2]

static char readChar ( final byte[]  buffer,
final int  offset 
)
static
307  {
308  return (char) ((buffer[offset+1] & 0xff) << 8
309  | (buffer[offset+0] & 0xff));
310  }

References LEDataInputStream.buffer.

◆ readDouble() [1/2]

final double readDouble ( ) throws IOException
183  {
184  return Double.longBitsToDouble(readLong());
185  }
final long readLong()
Definition: LEDataInputStream.java:134

References LEDataInputStream.readLong().

Referenced by LEDataInputStream.readDoubles().

◆ readDouble() [2/2]

static double readDouble ( final byte[]  buffer,
final int  offset 
)
static
341  {
342  return Double.longBitsToDouble(readLong(buffer,offset));
343  }

References LEDataInputStream.buffer, and LEDataInputStream.readLong().

◆ readDoubles()

double [] readDoubles ( int  nbValues) throws IOException

Read multiple values in one call.

Parameters
nbValuesnumber of valeus to read
Returns
array of values
Exceptions
java.io.IOException
194  {
195  final double[] array = new double[nbValues];
196  for (int i=0; i<nbValues; i++) {
197  array[i] = readDouble();
198  }
199  return array;
200  }
final double readDouble()
Definition: LEDataInputStream.java:183

References LEDataInputStream.readDouble().

◆ readFloat() [1/2]

final float readFloat ( ) throws IOException
163  {
164  return Float.intBitsToFloat(readInt());
165  }
final int readInt()
Definition: LEDataInputStream.java:109

References LEDataInputStream.readInt().

Referenced by LEDataInputStream.readFloats().

◆ readFloat() [2/2]

static float readFloat ( final byte[]  buffer,
final int  offset 
)
static
337  {
338  return Float.intBitsToFloat(readInt(buffer,offset));
339  }

References LEDataInputStream.buffer, and LEDataInputStream.readInt().

◆ readFloats()

float [] readFloats ( int  nbValues) throws IOException

Read multiple values in one call.

Parameters
nbValuesnumber of valeus to read
Returns
array of values
Exceptions
java.io.IOException
174  {
175  final float[] array = new float[nbValues];
176  for (int i=0; i<nbValues; i++) {
177  array[i] = readFloat();
178  }
179  return array;
180  }
final float readFloat()
Definition: LEDataInputStream.java:163

References LEDataInputStream.readFloat().

◆ readFully() [1/2]

final void readFully ( byte  b[]) throws IOException
210  {
211  ds.readFully(b, 0, b.length);
212  position+=b.length;
213  }

References LEDataInputStream.ds, and LEDataInputStream.position.

◆ readFully() [2/2]

final void readFully ( byte  b[],
int  off,
int  len 
) throws IOException
216  {
217  ds.readFully(b, off, len);
218  position+=len;
219  }

References LEDataInputStream.ds, and LEDataInputStream.position.

◆ readInt() [1/2]

final int readInt ( ) throws IOException
109  {
110  position+=4;
111  ds.readFully(buffer, 0, 4);
112  return (buffer[3]) << 24
113  | (buffer[2] & 0xff) << 16
114  | (buffer[1] & 0xff) << 8
115  | (buffer[0] & 0xff);
116  }

References LEDataInputStream.buffer, LEDataInputStream.ds, and LEDataInputStream.position.

Referenced by LEDataInputStream.readFloat(), and LEDataInputStream.readInts().

◆ readInt() [2/2]

static int readInt ( final byte[]  buffer,
final int  offset 
)
static
312  {
313  return (buffer[offset+3]) << 24
314  | (buffer[offset+2] & 0xff) << 16
315  | (buffer[offset+1] & 0xff) << 8
316  | (buffer[offset+0] & 0xff);
317  }

References LEDataInputStream.buffer.

◆ readInts()

int [] readInts ( int  nbValues) throws IOException

Read multiple values in one call.

Parameters
nbValuesnumber of valeus to read
Returns
array of values
Exceptions
java.io.IOException
125  {
126  final int[] array = new int[nbValues];
127  for (int i=0; i<nbValues; i++) {
128  array[i] = readInt();
129  }
130  return array;
131  }

References LEDataInputStream.readInt().

◆ readLine()

final String readLine ( ) throws IOException
259  {
260  return ds.readLine();
261  }

References LEDataInputStream.ds.

◆ readLong() [1/2]

final long readLong ( ) throws IOException
134  {
135  position+=8;
136  ds.readFully(buffer, 0, 8);
137  return (long) (buffer[7]) << 56
138  | (long) (buffer[6] & 0xff) << 48
139  | (long) (buffer[5] & 0xff) << 40
140  | (long) (buffer[4] & 0xff) << 32
141  | (long) (buffer[3] & 0xff) << 24
142  | (long) (buffer[2] & 0xff) << 16
143  | (long) (buffer[1] & 0xff) << 8
144  | (long) (buffer[0] & 0xff);
145  }

References LEDataInputStream.buffer, LEDataInputStream.ds, and LEDataInputStream.position.

Referenced by LEDataInputStream.readDouble(), and LEDataInputStream.readLongs().

◆ readLong() [2/2]

static long readLong ( final byte[]  buffer,
final int  offset 
)
static
326  {
327  return (long) (buffer[offset+7]) << 56
328  | (long) (buffer[offset+6] & 0xff) << 48
329  | (long) (buffer[offset+5] & 0xff) << 40
330  | (long) (buffer[offset+4] & 0xff) << 32
331  | (long) (buffer[offset+3] & 0xff) << 24
332  | (long) (buffer[offset+2] & 0xff) << 16
333  | (long) (buffer[offset+1] & 0xff) << 8
334  | (long) (buffer[offset+0] & 0xff);
335  }

References LEDataInputStream.buffer.

◆ readLongs()

long [] readLongs ( int  nbValues) throws IOException

Read multiple values in one call.

Parameters
nbValuesnumber of valeus to read
Returns
array of values
Exceptions
java.io.IOException
154  {
155  final long[] array = new long[nbValues];
156  for (int i=0; i<nbValues; i++) {
157  array[i] = readLong();
158  }
159  return array;
160  }

References LEDataInputStream.readLong().

◆ readShort() [1/2]

final short readShort ( ) throws IOException
56  {
57  position+=2;
58  ds.readFully(buffer, 0, 2);
59  return (short) ((buffer[1] & 0xff) << 8
60  | (buffer[0] & 0xff));
61  }

References LEDataInputStream.buffer, LEDataInputStream.ds, and LEDataInputStream.position.

Referenced by LEDataInputStream.readShorts().

◆ readShort() [2/2]

static short readShort ( final byte[]  buffer,
final int  offset 
)
static
298  {
299  return (short) ((buffer[offset+1] & 0xff) << 8
300  | (buffer[offset+0] & 0xff));
301  }

References LEDataInputStream.buffer.

◆ readShorts()

short [] readShorts ( int  nbValues) throws IOException

Read multiple values in one call.

Parameters
nbValuesnumber of valeus to read
Returns
array of values
Exceptions
java.io.IOException
70  {
71  final short[] array = new short[nbValues];
72  for (int i=0; i<nbValues; i++) {
73  array[i] = readShort();
74  }
75  return array;
76  }
final short readShort()
Definition: LEDataInputStream.java:56

References LEDataInputStream.readShort().

◆ readUnsignedByte() [1/2]

final int readUnsignedByte ( ) throws IOException
253  {
254  position++;
255  return ds.readUnsignedByte();
256  }

References LEDataInputStream.ds, and LEDataInputStream.position.

◆ readUnsignedByte() [2/2]

static short readUnsignedByte ( final byte[]  buffer,
final int  offset 
)
static
294  {
295  return (short) (buffer[offset] & 0xff);
296  }

References LEDataInputStream.buffer.

◆ readUnsignedInt()

static long readUnsignedInt ( final byte[]  buffer,
final int  offset 
)
static
319  {
320  return (long) (buffer[offset+3] & 0xff) << 24
321  | (long) (buffer[offset+2] & 0xff) << 16
322  | (long) (buffer[offset+1] & 0xff) << 8
323  | (long) (buffer[offset+0] & 0xff);
324  }

References LEDataInputStream.buffer.

◆ readUnsignedShort() [1/2]

final int readUnsignedShort ( ) throws IOException
79  {
80  position+=2;
81  ds.readFully(buffer, 0, 2);
82  return ((buffer[1] & 0xff) << 8 | (buffer[0] & 0xff));
83  }

References LEDataInputStream.buffer, LEDataInputStream.ds, and LEDataInputStream.position.

Referenced by LEDataInputStream.readUnsignedShorts().

◆ readUnsignedShort() [2/2]

static int readUnsignedShort ( final byte[]  buffer,
final int  offset 
)
static
303  {
304  return ((buffer[offset+1] & 0xff) << 8 | (buffer[offset+0] & 0xff));
305  }

References LEDataInputStream.buffer.

◆ readUnsignedShorts()

int [] readUnsignedShorts ( int  nbValues) throws IOException

Read multiple values in one call.

Parameters
nbValuesnumber of valeus to read
Returns
array of values
Exceptions
java.io.IOException
92  {
93  final int[] array = new int[nbValues];
94  for (int i=0; i<nbValues; i++) {
95  array[i] = readUnsignedShort();
96  }
97  return array;
98  }
final int readUnsignedShort()
Definition: LEDataInputStream.java:79

References LEDataInputStream.readUnsignedShort().

◆ readUTF()

final String readUTF ( ) throws IOException
264  {
265  return ds.readUTF();
266  }

References LEDataInputStream.ds.

◆ realign()

int realign ( int  blockSize) throws IOException

Ralign stream position, skipping any remaining byte to match given block size.

Older formats or javascript buffer requiere to be aligned on 2, 4 or 8 bytes (short,int,float,double) to read datas.

Parameters
blockSize
Returns
number of bytes skipped
276  {
277  final long position = getPosition();
278  final long res = position % blockSize;
279  if (res == 0) return 0;
280  try {
281  skipFully((int) (blockSize-res));
282  } catch (EOFException ex) {
283  return -1;
284  }
285  return (int) res;
286  }
final void skipFully(int n)
Definition: LEDataInputStream.java:228
long getPosition()
Get current stream position from the first written byte.
Definition: LEDataInputStream.java:46

References LEDataInputStream.getPosition(), LEDataInputStream.position, and LEDataInputStream.skipFully().

◆ skipBytes()

final int skipBytes ( int  n) throws IOException
222  {
223  int nb = ds.skipBytes(n);
224  position+=nb;
225  return nb;
226  }

References LEDataInputStream.ds, and LEDataInputStream.position.

Referenced by LEDataInputStream.skipFully().

◆ skipFully()

final void skipFully ( int  n) throws IOException
228  {
229  while (n > 0) {
230  n -= skipBytes(n);
231  }
232  }
final int skipBytes(int n)
Definition: LEDataInputStream.java:222

References LEDataInputStream.skipBytes().

Referenced by LEDataInputStream.realign().

Member Data Documentation

◆ buffer

◆ ds

◆ in

final InputStream in
private

◆ position