01: /*
02: * @(#)readLong.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: * readLong(DataInput)
16: * readLong(DataInput, long[] data, int offset, int size)
17: */
18: public class readLong extends PnutsFunction {
19:
20: public readLong() {
21: super ("readLong");
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 Long(din.readLong());
34: } else if (nargs == 4) {
35: DataInput din = (DataInput) args[0];
36: long[] dest = (long[]) 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.readLong();
41: }
42: return null;
43: } else {
44: undefined(args, context);
45: return null;
46: }
47: } catch (IOException e) {
48: throw new PnutsException(e, context);
49: }
50: }
51:
52: public String toString() {
53: return "function readLong(DataInput {, long[] data, int offset, int size})";
54: }
55: }
|