01: /*
02: * @(#)readDouble.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: * readDouble(DataInput)
16: * readDouble(DataInput, double[] data, int offset, int size)
17: */
18: public class readDouble extends PnutsFunction {
19:
20: public readDouble() {
21: super ("readDouble");
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 Double(din.readDouble());
34: } else if (nargs == 4) {
35: DataInput din = (DataInput) args[0];
36: double[] dest = (double[]) 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.readDouble();
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 readDouble(DataInput {, double[] data, int offset, int size })";
54: }
55: }
|