KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > util > Buffer


1 package org.jgroups.util;
2
3 /**
4  * Buffer with an offset and length. Will be replaced with NIO equivalent once JDK 1.4 becomes baseline
5  * @author Bela Ban
6  * @version $Id: Buffer.java,v 1.2 2005/04/11 12:54:08 belaban Exp $
7  */

8 public class Buffer {
9     byte[] buf;
10     int offset;
11     int length;
12
13     public Buffer(byte[] buf, int offset, int length) {
14         this.buf=buf;
15         this.offset=offset;
16         this.length=length;
17     }
18
19     public byte[] getBuf() {
20         return buf;
21     }
22
23     public void setBuf(byte[] buf) {
24         this.buf=buf;
25     }
26
27     public int getOffset() {
28         return offset;
29     }
30
31     public void setOffset(int offset) {
32         this.offset=offset;
33     }
34
35     public int getLength() {
36         return length;
37     }
38
39     public void setLength(int length) {
40         this.length=length;
41     }
42
43     public String JavaDoc toString() {
44         StringBuffer JavaDoc sb=new StringBuffer JavaDoc();
45         sb.append(buf != null? buf.length : '0').append(" bytes");
46         if(offset > 0)
47             sb.append("offset=").append(offset).append(", len=").append(length).append(")");
48         return sb.toString();
49     }
50 }
51
Popular Tags