01: /*
02: * @(#)writeBoolean.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: * writeBoolean(DataOutput dout, boolean value)
16: * writeBoolean(DataOutput dout, boolean[] src, int offset, int len)
17: */
18: public class writeBoolean extends PnutsFunction {
19:
20: public writeBoolean() {
21: super ("writeBoolean");
22: }
23:
24: public boolean defined(int narg) {
25: return (narg == 2 || narg == 4);
26: }
27:
28: protected Object exec(Object[] args, Context context) {
29: int nargs = args.length;
30: try {
31: if (nargs == 2) {
32: DataOutput dout = (DataOutput) args[0];
33: boolean value = ((Boolean) args[1]).booleanValue();
34: dout.writeBoolean(value);
35: return new Integer(1);
36: } else if (nargs == 4) {
37: DataOutput dout = (DataOutput) args[0];
38: boolean[] src = (boolean[]) args[1];
39: int offset = ((Integer) args[2]).intValue();
40: int size = ((Integer) args[3]).intValue();
41:
42: for (int i = 0; i < size; i++) {
43: dout.writeBoolean(src[offset + i]);
44: }
45: return new Integer(size);
46: } else {
47: undefined(args, context);
48: return null;
49: }
50: } catch (IOException e) {
51: throw new PnutsException(e, context);
52: }
53: }
54:
55: public String toString() {
56: return "function writeBoolean(DataOutput dout , { boolean value | boolean[] src, int offset, int len })";
57: }
58: }
|