KickJava   Java API By Example, From Geeks To Geeks.

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


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.DataOutput JavaDoc;
7 import java.io.DataInput JavaDoc;
8 import java.io.IOException JavaDoc;
9
10 /** A base class for Writables that provides version checking.
11  *
12  * <p>This is useful when a class may evolve, so that instances written by the
13  * old version of the class may still be processed by the new version. To
14  * handle this situation, {@link #readFields(DataInput)}
15  * implementations should catch {@link VersionMismatchException}.
16  *
17  * @author Doug Cutting
18  */

19 public abstract class VersionedWritable implements Writable {
20
21   /** Return the version number of the current implementation. */
22   public abstract byte getVersion();
23     
24   // javadoc from Writable
25
public void write(DataOutput JavaDoc out) throws IOException JavaDoc {
26     out.writeByte(getVersion()); // store version
27
}
28
29   // javadoc from Writable
30
public void readFields(DataInput JavaDoc in) throws IOException JavaDoc {
31     byte version = in.readByte(); // read version
32
if (version != getVersion())
33       throw new VersionMismatchException(getVersion(),version);
34   }
35
36     
37 }
38
Popular Tags