001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.activemq.util; 019 020public class ByteSequence { 021 022 public byte[] data; 023 public int offset; 024 public int length; 025 026 public ByteSequence(byte data[]) { 027 this.data = data; 028 this.offset = 0; 029 this.length = data.length; 030 } 031 032 public ByteSequence(byte data[], int offset, int length) { 033 this.data = data; 034 this.offset = offset; 035 this.length = length; 036 } 037 038 public byte[] getData() { 039 return data; 040 } 041 042 public int getLength() { 043 return length; 044 } 045 046 public int getOffset() { 047 return offset; 048 } 049 050 public void setData(byte[] data) { 051 this.data = data; 052 } 053 054 public void setLength(int length) { 055 this.length = length; 056 } 057 058 public void setOffset(int offset) { 059 this.offset = offset; 060 } 061 062 public void compact() { 063 if (length != data.length) { 064 byte t[] = new byte[length]; 065 System.arraycopy(data, offset, t, 0, length); 066 data = t; 067 offset = 0; 068 } 069 } 070 071}