Skip to content

Commit 92f0193

Browse files
committed
add slice buffer
1 parent b461f7d commit 92f0193

File tree

12 files changed

+735
-9
lines changed

12 files changed

+735
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
- Add more tests.
1313
- Add `JavaDoc`.
1414

15-
## [1.17.3](https://github.com/appulse-projects/utils-java/releases/tag/1.17.3) - 2020-02-25
15+
## [1.18.0](https://github.com/appulse-projects/utils-java/releases/tag/1.18.0) - 2020-02-25
1616

1717
### Added
1818

19-
- A **read-only** implementation of `Bytes`.
19+
- A **read-only** implementation of `Bytes`;
20+
- Now it's possible to create a diffirent `slice`s of `Bytes`.
2021

2122
### Changed
2223

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ limitations under the License.
2424

2525
<groupId>io.appulse</groupId>
2626
<artifactId>utils-java</artifactId>
27-
<version>1.17.3</version>
27+
<version>1.18.0</version>
2828
<packaging>jar</packaging>
2929

3030
<properties>
@@ -66,7 +66,7 @@ limitations under the License.
6666
<url>https://github.com/appulse-projects/utils-java</url>
6767
<connection>scm:git:https://github.com/appulse-projects/utils-java.git</connection>
6868
<developerConnection>scm:git:https://github.com/appulse-projects/utils-java.git</developerConnection>
69-
<tag>1.17.3</tag>
69+
<tag>1.18.0</tag>
7070
</scm>
7171

7272
<distributionManagement>

src/main/java/io/appulse/utils/Bytes.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static Bytes resizableArray (int initialSize) {
133133
*
134134
* @return the new {@link Bytes} read-only instance
135135
*
136-
* @since 1.17.3
136+
* @since 1.18.0
137137
*/
138138
static Bytes readOnly (byte[] bytes) {
139139
val delegate = Bytes.wrap(bytes);
@@ -149,7 +149,7 @@ static Bytes readOnly (byte[] bytes) {
149149
*
150150
* @return the new {@link Bytes} read-only instance
151151
*
152-
* @since 1.17.3
152+
* @since 1.18.0
153153
*/
154154
static Bytes readOnly (ByteBuffer buffer) {
155155
val delegate = Bytes.wrap(buffer);
@@ -165,7 +165,7 @@ static Bytes readOnly (ByteBuffer buffer) {
165165
*
166166
* @return the new {@link Bytes} read-only instance
167167
*
168-
* @since 1.17.3
168+
* @since 1.18.0
169169
*/
170170
static Bytes readOnly (Bytes delegate) {
171171
return new BytesReadOnly(delegate);
@@ -1827,4 +1827,13 @@ static Bytes readOnly (Bytes delegate) {
18271827
* @return the copy of the array that backs this buffer
18281828
*/
18291829
byte[] arrayCopy ();
1830+
1831+
/**
1832+
* Creates a new {@link BytesSliceBuilder} instance for making the buffer's slize.
1833+
*
1834+
* @return the {@link BytesSliceBuilder} instance
1835+
*
1836+
* @since 1.18.0
1837+
*/
1838+
BytesSliceBuilder slice ();
18301839
}

src/main/java/io/appulse/utils/BytesAbstract.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,11 @@ public byte[] arrayCopy () {
479479
return Arrays.copyOfRange(array(), 0, writerIndex());
480480
}
481481

482+
@Override
483+
public BytesSliceBuilder slice () {
484+
return new BytesSliceBuilder(this);
485+
}
486+
482487
@Override
483488
public String toString () {
484489
return new StringBuilder()

src/main/java/io/appulse/utils/BytesByteBuf.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424

2525
import io.netty.buffer.ByteBuf;
2626
import io.netty.buffer.Unpooled;
27+
import lombok.EqualsAndHashCode;
2728
import lombok.NonNull;
2829
import lombok.experimental.FieldDefaults;
2930
import lombok.val;
3031

3132
@SuppressWarnings("PMD.LinguisticNaming")
3233
@FieldDefaults(level = PRIVATE)
34+
@EqualsAndHashCode(callSuper = true)
3335
public final class BytesByteBuf extends BytesAbstract {
3436

3537
public static BytesByteBuf allocate (int size) {

src/main/java/io/appulse/utils/BytesByteBuffer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
import java.nio.charset.Charset;
2323
import java.util.Arrays;
2424

25+
import lombok.EqualsAndHashCode;
2526
import lombok.NonNull;
2627
import lombok.experimental.FieldDefaults;
2728
import lombok.val;
2829

29-
@FieldDefaults(level = PRIVATE)
3030
@SuppressWarnings("PMD.LinguisticNaming")
31+
@FieldDefaults(level = PRIVATE)
32+
@EqualsAndHashCode(callSuper = true)
3133
class BytesByteBuffer extends BytesAbstract {
3234

3335
static BytesByteBuffer copy (@NonNull ByteBuffer buffer) {

src/main/java/io/appulse/utils/BytesExtendableArray.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919
import java.util.Arrays;
2020

21+
import lombok.EqualsAndHashCode;
2122
import lombok.val;
2223

24+
@EqualsAndHashCode(callSuper = true)
2325
class BytesExtendableArray extends BytesFixedArray {
2426

2527
/**

src/main/java/io/appulse/utils/BytesFixedArray.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
import java.nio.charset.Charset;
2222
import java.util.Arrays;
2323

24+
import lombok.EqualsAndHashCode;
2425
import lombok.NonNull;
2526
import lombok.experimental.FieldDefaults;
2627
import lombok.val;
2728

28-
@FieldDefaults(level = PROTECTED)
2929
@SuppressWarnings("PMD.LinguisticNaming")
30+
@FieldDefaults(level = PROTECTED)
31+
@EqualsAndHashCode(callSuper = true)
3032
class BytesFixedArray extends BytesAbstract {
3133

3234
static BytesFixedArray copy (@NonNull byte[] bytes) {
@@ -52,6 +54,10 @@ static BytesFixedArray copy (@NonNull byte[] bytes) {
5254
writerIndex(bytes.length);
5355
}
5456

57+
protected BytesFixedArray () {
58+
super();
59+
}
60+
5561
@Override
5662
public boolean isAutoResizable () {
5763
return false;

src/main/java/io/appulse/utils/BytesReadOnly.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121

2222
import java.nio.charset.Charset;
2323

24+
import lombok.EqualsAndHashCode;
2425
import lombok.RequiredArgsConstructor;
2526
import lombok.experimental.FieldDefaults;
2627
import lombok.val;
2728

2829
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
2930
@FieldDefaults(level = PRIVATE)
31+
@EqualsAndHashCode(callSuper = true)
3032
@RequiredArgsConstructor(access = PACKAGE)
3133
class BytesReadOnly extends BytesAbstract {
3234

0 commit comments

Comments
 (0)