KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > util > ByteSequence


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * 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
19 package org.apache.activemq.util;
20
21 public class ByteSequence {
22     
23     public byte[] data;
24     public int offset;
25     public int length;
26
27     public ByteSequence(byte data[]) {
28         this.data = data;
29         this.offset = 0;
30         this.length = data.length;
31     }
32
33     public ByteSequence(byte data[], int offset, int length) {
34         this.data = data;
35         this.offset = offset;
36         this.length = length;
37     }
38     
39     public byte[] getData() {
40         return data;
41     }
42     public int getLength() {
43         return length;
44     }
45     public int getOffset() {
46         return offset;
47     }
48     public void setData(byte[] data) {
49         this.data = data;
50     }
51     public void setLength(int length) {
52         this.length = length;
53     }
54     public void setOffset(int offset) {
55         this.offset = offset;
56     }
57     
58     public void compact() {
59         if( length != data.length ) {
60             byte t[] = new byte[length];
61             System.arraycopy(data, offset, t, 0, length);
62             data=t;
63             offset=0;
64         }
65     }
66
67 }
68
Popular Tags