KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > io > BytesWritable


1 /* Copyright (c) 2003 The Nutch Organization. All rights reserved. */
2 /* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
3
4 package net.nutch.io;
5
6 import java.io.IOException JavaDoc;
7 import java.io.DataInput JavaDoc;
8 import java.io.DataOutput JavaDoc;
9
10 /** A Writable for byte arrays.
11  *
12  * @author Doug Cutting
13  */

14 public class BytesWritable implements Writable {
15   private byte[] bytes;
16
17   public BytesWritable() {}
18
19   public BytesWritable(byte[] bytes) {
20     this.bytes = bytes;
21   }
22
23   public byte[] get() {
24     return bytes;
25   }
26
27   public void readFields(DataInput JavaDoc in) throws IOException JavaDoc {
28     bytes = new byte[in.readInt()];
29     in.readFully(bytes, 0, bytes.length);
30   }
31
32   public void write(DataOutput JavaDoc out) throws IOException JavaDoc {
33     out.writeInt(bytes.length);
34     out.write(bytes);
35   }
36
37 }
38
Popular Tags