01: /*
02: * @(#)readUnsignedShort.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.io;
10:
11: import pnuts.lang.*;
12: import java.io.*;
13:
14: /**
15: * readUnsignedShort(DataInput)
16: * readUnsignedShort(DataInput, int[] data, int offset, int size)
17: */
18: public class readUnsignedShort extends PnutsFunction {
19:
20: public readUnsignedShort() {
21: super ("readUnsignedShort");
22: }
23:
24: public boolean defined(int narg) {
25: return (narg == 1 || narg == 4);
26: }
27:
28: protected Object exec(Object[] args, Context context) {
29: int nargs = args.length;
30: try {
31: if (nargs == 1) {
32: DataInput din = (DataInput) args[0];
33: return new Integer(din.readUnsignedShort());
34: } else if (nargs == 4) {
35: DataInput din = (DataInput) args[0];
36: int[] dest = (int[]) args[1];
37: int offset = ((Integer) args[2]).intValue();
38: int size = ((Integer) args[3]).intValue();
39: for (int i = 0; i < size; i++) {
40: dest[offset + i] = din.readUnsignedShort();
41: }
42: return null;
43: }
44: } catch (IOException e) {
45: throw new PnutsException(e, context);
46: }
47: undefined(args, context);
48: return null;
49: }
50:
51: public String toString() {
52: return "function readUnsignedShort(DataInput {, int[] data, int offset, int size })";
53: }
54: }
|