Skip to content

Commit 9c5b805

Browse files
committed
Refactoring Bytes
1 parent bd39e6f commit 9c5b805

6 files changed

Lines changed: 217 additions & 137 deletions

File tree

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.0.0</version>
27+
<version>1.0.1</version>
2828
<packaging>jar</packaging>
2929

3030
<properties>
@@ -62,7 +62,7 @@ limitations under the License.
6262
<url>https://github.com/appulse-projects/utils-java</url>
6363
<connection>scm:git:https://github.com/appulse-projects/utils-java.git</connection>
6464
<developerConnection>scm:git:https://github.com/appulse-projects/utils-java.git</developerConnection>
65-
<tag>0.0.1</tag>
65+
<tag>1.0.1</tag>
6666
</scm>
6767

6868
<distributionManagement>

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ public static Bytes allocate (int capacity) {
7272
@Delegate
7373
BytesDelegatePuts puts;
7474

75-
@Delegate
76-
BytesDelegatePutsAs putsAs;
77-
7875
@Delegate
7976
BytesDelegateGets gets;
8077

@@ -84,9 +81,7 @@ public static Bytes allocate (int capacity) {
8481

8582
private Bytes (ByteBuffer buffer) {
8683
puts = new BytesDelegatePuts(this);
87-
putsAs = new BytesDelegatePutsAs(this);
8884
gets = new BytesDelegateGets(this);
89-
9085
this.buffer = buffer;
9186
}
9287

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
package io.appulse.utils;
1818

19+
import static java.nio.charset.StandardCharsets.UTF_8;
1920
import static lombok.AccessLevel.PRIVATE;
2021

22+
import java.nio.charset.Charset;
23+
2124
import lombok.RequiredArgsConstructor;
2225
import lombok.experimental.FieldDefaults;
2326

@@ -83,4 +86,20 @@ public double getDouble () {
8386
public double getDouble (int index) {
8487
return bytes.getBuffer().getDouble(index);
8588
}
89+
90+
public String getString () {
91+
return new String(bytes.getBytes(), UTF_8);
92+
}
93+
94+
public String getString (Charset charset) {
95+
return new String(bytes.getBytes(), charset);
96+
}
97+
98+
public String getString (int length) {
99+
return new String(bytes.getBytes(length), UTF_8);
100+
}
101+
102+
public String getString (int length, Charset charset) {
103+
return new String(bytes.getBytes(length), charset);
104+
}
86105
}

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

Lines changed: 191 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.appulse.utils;
1818

19+
import static io.appulse.utils.BytesUtil.align;
20+
import static io.appulse.utils.BytesUtil.asBytes;
1921
import static java.nio.charset.StandardCharsets.UTF_8;
2022
import static lombok.AccessLevel.PRIVATE;
2123

@@ -29,58 +31,227 @@
2931
* @author Artem Labazin
3032
* @since 1.0.0
3133
*/
34+
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
3235
@RequiredArgsConstructor
3336
@FieldDefaults(level = PRIVATE, makeFinal = true)
3437
final class BytesDelegatePuts {
3538

3639
Bytes bytes;
3740

41+
public Bytes putNB (byte value, int length) {
42+
return bytes.put(align(asBytes(value), length));
43+
}
44+
45+
public Bytes putNB (int index, byte value, int length) {
46+
return bytes.put(index, align(asBytes(value), length));
47+
}
48+
49+
public Bytes putNB (short value, int length) {
50+
return bytes.put(align(asBytes(value), length));
51+
}
52+
53+
public Bytes putNB (int index, short value, int length) {
54+
return bytes.put(index, align(asBytes(value), length));
55+
}
56+
57+
public Bytes putNB (int value, int length) {
58+
return bytes.put(align(asBytes(value), length));
59+
}
60+
61+
public Bytes putNB (int index, int value, int length) {
62+
return bytes.put(index, align(asBytes(value), length));
63+
}
64+
65+
public Bytes putNB (long value, int length) {
66+
return bytes.put(align(asBytes(value), length));
67+
}
68+
69+
public Bytes putNB (int index, long value, int length) {
70+
return bytes.put(index, align(asBytes(value), length));
71+
}
72+
73+
public Bytes putNB (byte[] value, int length) {
74+
return bytes.put(align(value, length));
75+
}
76+
77+
public Bytes putNB (int index, byte[] value, int length) {
78+
return bytes.put(index, align(value, length));
79+
}
80+
81+
public Bytes put1B (byte value) {
82+
return bytes.put(value);
83+
}
84+
85+
public Bytes put1B (int index, byte value) {
86+
return bytes.put(value);
87+
}
88+
89+
public Bytes put1B (short value) {
90+
return bytes.put((byte) value);
91+
}
92+
93+
public Bytes put1B (int index, short value) {
94+
return bytes.put(index, (byte) value);
95+
}
96+
97+
public Bytes put1B (int value) {
98+
return bytes.put((byte) value);
99+
}
100+
101+
public Bytes put1B (int index, int value) {
102+
return bytes.put(index, (byte) value);
103+
}
104+
105+
public Bytes put1B (long value) {
106+
return bytes.put((byte) value);
107+
}
108+
109+
public Bytes put1B (int index, long value) {
110+
return bytes.put(index, (byte) value);
111+
}
112+
113+
public Bytes put2B (byte value) {
114+
return putNB(value, 2);
115+
}
116+
117+
public Bytes put2B (int index, byte value) {
118+
return putNB(index, value, 2);
119+
}
120+
121+
public Bytes put2B (short value) {
122+
return putNB(value, 2);
123+
}
124+
125+
public Bytes put2B (int index, short value) {
126+
return putNB(index, value, 2);
127+
}
128+
129+
public Bytes put2B (int value) {
130+
return putNB(value, 2);
131+
}
132+
133+
public Bytes put2B (int index, int value) {
134+
return putNB(index, value, 2);
135+
}
136+
137+
public Bytes put2B (long value) {
138+
return putNB(value, 2);
139+
}
140+
141+
public Bytes put2B (int index, long value) {
142+
return putNB(index, value, 2);
143+
}
144+
145+
public Bytes put4B (byte value) {
146+
return putNB(value, 4);
147+
}
148+
149+
public Bytes put4B (int index, byte value) {
150+
return putNB(index, value, 4);
151+
}
152+
153+
public Bytes put4B (short value) {
154+
return putNB(value, 4);
155+
}
156+
157+
public Bytes put4B (int index, short value) {
158+
return putNB(index, value, 4);
159+
}
160+
161+
public Bytes put4B (int value) {
162+
return putNB(value, 4);
163+
}
164+
165+
public Bytes put4B (int index, int value) {
166+
return putNB(index, value, 4);
167+
}
168+
169+
public Bytes put4B (long value) {
170+
return putNB(value, 4);
171+
}
172+
173+
public Bytes put4B (int index, long value) {
174+
return putNB(index, value, 4);
175+
}
176+
177+
public Bytes put8B (byte value) {
178+
return putNB(value, 8);
179+
}
180+
181+
public Bytes put8B (int index, byte value) {
182+
return putNB(index, value, 8);
183+
}
184+
185+
public Bytes put8B (short value) {
186+
return putNB(value, 8);
187+
}
188+
189+
public Bytes put8B (int index, short value) {
190+
return putNB(index, value, 8);
191+
}
192+
193+
public Bytes put8B (int value) {
194+
return putNB(value, 8);
195+
}
196+
197+
public Bytes put8B (int index, int value) {
198+
return putNB(index, value, 8);
199+
}
200+
201+
public Bytes put8B (long value) {
202+
return putNB(value, 8);
203+
}
204+
205+
public Bytes put8B (int index, long value) {
206+
return putNB(index, value, 8);
207+
}
208+
38209
public Bytes put (short value) {
39-
return bytes.put(BytesUtil.asBytes(value));
210+
return bytes.put(asBytes(value));
40211
}
41212

42213
public Bytes put (int index, short value) {
43-
return bytes.put(index, BytesUtil.asBytes(value));
214+
return bytes.put(index, asBytes(value));
44215
}
45216

46217
public Bytes put (int value) {
47-
return bytes.put(BytesUtil.asBytes(value));
218+
return bytes.put(asBytes(value));
48219
}
49220

50221
public Bytes put (int index, int value) {
51-
return bytes.put(index, BytesUtil.asBytes(value));
222+
return bytes.put(index, asBytes(value));
52223
}
53224

54225
public Bytes put (long value) {
55-
return bytes.put(BytesUtil.asBytes(value));
226+
return bytes.put(asBytes(value));
56227
}
57228

58229
public Bytes put (int index, long value) {
59-
return bytes.put(index, BytesUtil.asBytes(value));
230+
return bytes.put(index, asBytes(value));
60231
}
61232

62233
public Bytes put (float value) {
63-
return bytes.put(BytesUtil.asBytes(value));
234+
return bytes.put(asBytes(value));
64235
}
65236

66237
public Bytes put (int index, float value) {
67-
return bytes.put(index, BytesUtil.asBytes(value));
238+
return bytes.put(index, asBytes(value));
68239
}
69240

70241
public Bytes put (double value) {
71-
return bytes.put(BytesUtil.asBytes(value));
242+
return bytes.put(asBytes(value));
72243
}
73244

74245
public Bytes put (int index, double value) {
75-
return bytes.put(index, BytesUtil.asBytes(value));
246+
return bytes.put(index, asBytes(value));
76247
}
77248

78249
public Bytes put (char value) {
79-
return bytes.put(BytesUtil.asBytes(value));
250+
return bytes.put(asBytes(value));
80251
}
81252

82253
public Bytes put (int index, char value) {
83-
return bytes.put(index, BytesUtil.asBytes(value));
254+
return bytes.put(index, asBytes(value));
84255
}
85256

86257
public Bytes put (String value) {
@@ -98,4 +269,12 @@ public Bytes put (int index, String value) {
98269
public Bytes put (int index, String value, Charset charset) {
99270
return bytes.put(index, value.getBytes(charset));
100271
}
272+
273+
public Bytes put (Bytes value) {
274+
return bytes.put(value.array());
275+
}
276+
277+
public Bytes put (int index, Bytes value) {
278+
return bytes.put(index, value.array());
279+
}
101280
}

0 commit comments

Comments
 (0)