source: proiecte/HadoopJUnit/hadoop-0.20.1/src/test/testjar/ExternalWritable.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package testjar;
20
21import java.io.DataInput;
22import java.io.DataOutput;
23import java.io.IOException;
24
25import org.apache.hadoop.io.WritableComparable;
26
27/**
28 * This is an example simple writable class.  This is used as a class external
29 * to the Hadoop IO classes for testing of user Writable classes.
30 *
31 */
32public class ExternalWritable
33  implements WritableComparable {
34
35  private String message = null;
36 
37  public ExternalWritable() {
38   
39  }
40 
41  public ExternalWritable(String message) {
42    this.message = message;
43  }
44 
45  public String getMessage() {
46    return message;
47  }
48
49  public void setMessage(String message) {
50    this.message = message;
51  }
52
53  public void readFields(DataInput in)
54    throws IOException {
55   
56    message = null;
57    boolean hasMessage = in.readBoolean();
58    if (hasMessage) {
59      message = in.readUTF();   
60    }
61  }
62
63  public void write(DataOutput out)
64    throws IOException {
65   
66    boolean hasMessage = (message != null && message.length() > 0);
67    out.writeBoolean(hasMessage);
68    if (hasMessage) {
69      out.writeUTF(message);
70    }
71  }
72 
73  public int compareTo(Object o) {
74   
75    if (!(o instanceof ExternalWritable)) {
76      throw new IllegalArgumentException("Input not an ExternalWritable");
77    }
78   
79    ExternalWritable that = (ExternalWritable)o;
80    return this.message.compareTo(that.message);
81  }
82
83  public String toString() {
84    return this.message;
85  }
86}
Note: See TracBrowser for help on using the repository browser.