Skip to content

Commit 4c06841

Browse files
committed
buffer: remove deprecated methods
1 parent 178d533 commit 4c06841

9 files changed

Lines changed: 15 additions & 285 deletions

File tree

jooby/src/main/java/io/jooby/buffer/DataBuffer.java

Lines changed: 1 addition & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -95,33 +95,6 @@ public interface DataBuffer {
9595
*/
9696
int capacity();
9797

98-
/**
99-
* Set the number of bytes that this buffer can contain.
100-
*
101-
* <p>If the new capacity is lower than the current capacity, the contents of this buffer will be
102-
* truncated. If the new capacity is higher than the current capacity, it will be expanded.
103-
*
104-
* @param capacity the new capacity
105-
* @return this buffer
106-
* @deprecated as of 6.0, in favor of {@link #ensureWritable(int)}, which has different semantics
107-
*/
108-
@Deprecated(since = "6.0")
109-
DataBuffer capacity(int capacity);
110-
111-
/**
112-
* Ensure that the current buffer has enough {@link #writableByteCount()} to write the amount of
113-
* data given as an argument. If not, the missing capacity will be added to the buffer.
114-
*
115-
* @param capacity the writable capacity to check for
116-
* @return this buffer
117-
* @since 5.1.4
118-
* @deprecated since 6.0, in favor of {@link #ensureWritable(int)}
119-
*/
120-
@Deprecated(since = "6.0")
121-
default DataBuffer ensureCapacity(int capacity) {
122-
return ensureWritable(capacity);
123-
}
124-
12598
/**
12699
* Ensure that the current buffer has enough {@link #writableByteCount()} to write the amount of
127100
* data given as an argument. If not, the missing capacity will be added to the buffer.
@@ -300,51 +273,11 @@ default DataBuffer write(CharSequence charSequence, Charset charset) {
300273
return this;
301274
}
302275

303-
/**
304-
* Create a new {@code DataBuffer} whose contents is a shared subsequence of this data buffer's
305-
* content. Data between this data buffer and the returned buffer is shared; though changes in the
306-
* returned buffer's position will not be reflected in the reading nor writing position of this
307-
* data buffer.
308-
*
309-
* <p><strong>Note</strong> that this method will <strong>not</strong> call {@link
310-
* DataBufferUtils#retain(DataBuffer)} on the resulting slice: the reference count will not be
311-
* increased.
312-
*
313-
* @param index the index at which to start the slice
314-
* @param length the length of the slice
315-
* @return the specified slice of this data buffer
316-
* @deprecated as of 6.0, in favor of {@link #split(int)}, which has different semantics
317-
*/
318-
@Deprecated(since = "6.0")
319-
DataBuffer slice(int index, int length);
320-
321-
/**
322-
* Create a new {@code DataBuffer} whose contents is a shared, retained subsequence of this data
323-
* buffer's content. Data between this data buffer and the returned buffer is shared; though
324-
* changes in the returned buffer's position will not be reflected in the reading nor writing
325-
* position of this data buffer.
326-
*
327-
* <p><strong>Note</strong> that unlike {@link #slice(int, int)}, this method
328-
* <strong>will</strong> call {@link DataBufferUtils#retain(DataBuffer)} (or equivalent) on the
329-
* resulting slice.
330-
*
331-
* @param index the index at which to start the slice
332-
* @param length the length of the slice
333-
* @return the specified, retained slice of this data buffer
334-
* @since 5.2
335-
* @deprecated as of 6.0, in favor of {@link #split(int)}, which has different semantics
336-
*/
337-
@Deprecated(since = "6.0")
338-
default DataBuffer retainedSlice(int index, int length) {
339-
return DataBufferUtils.retain(slice(index, length));
340-
}
341-
342276
/**
343277
* Splits this data buffer into two at the given index.
344278
*
345279
* <p>Data that precedes the {@code index} will be returned in a new buffer, while this buffer
346-
* will contain data that follows after {@code index}. Memory between the two buffers is shared,
347-
* but independent and cannot overlap (unlike {@link #slice(int, int) slice}).
280+
* will contain data that follows after {@code index}. Memory between the two buffers is shared.
348281
*
349282
* <p>The {@linkplain #readPosition() read} and {@linkplain #writePosition() write} position of
350283
* the returned buffer are truncated to fit within the buffers {@linkplain #capacity() capacity}
@@ -357,64 +290,6 @@ default DataBuffer retainedSlice(int index, int length) {
357290
*/
358291
DataBuffer split(int index);
359292

360-
/**
361-
* Expose this buffer's bytes as a {@link ByteBuffer}. Data between this {@code DataBuffer} and
362-
* the returned {@code ByteBuffer} is shared; though changes in the returned buffer's {@linkplain
363-
* ByteBuffer#position() position} will not be reflected in the reading nor writing position of
364-
* this data buffer.
365-
*
366-
* @return this data buffer as a byte buffer
367-
* @deprecated as of 6.0, in favor of {@link #toByteBuffer(ByteBuffer)}, {@link
368-
* #readableByteBuffers()}, or {@link #writableByteBuffers()}.
369-
*/
370-
@Deprecated(since = "6.0")
371-
ByteBuffer asByteBuffer();
372-
373-
/**
374-
* Expose a subsequence of this buffer's bytes as a {@link ByteBuffer}. Data between this {@code
375-
* DataBuffer} and the returned {@code ByteBuffer} is shared; though changes in the returned
376-
* buffer's {@linkplain ByteBuffer#position() position} will not be reflected in the reading nor
377-
* writing position of this data buffer.
378-
*
379-
* @param index the index at which to start the byte buffer
380-
* @param length the length of the returned byte buffer
381-
* @return this data buffer as a byte buffer
382-
* @since 5.0.1
383-
* @deprecated as of 6.0, in favor of {@link #toByteBuffer(int, ByteBuffer, int, int)}, {@link
384-
* #readableByteBuffers()}, or {@link #writableByteBuffers()}.
385-
*/
386-
@Deprecated(since = "6.0")
387-
ByteBuffer asByteBuffer(int index, int length);
388-
389-
/**
390-
* Returns a {@link ByteBuffer} representation of this data buffer. Data between this {@code
391-
* DataBuffer} and the returned {@code ByteBuffer} is <strong>not</strong> shared.
392-
*
393-
* @return this data buffer as a byte buffer
394-
* @since 6.0
395-
* @see #readableByteBuffers()
396-
* @see #writableByteBuffers()
397-
* @deprecated as of 6.0.5, in favor of {@link #toByteBuffer(ByteBuffer)}
398-
*/
399-
@Deprecated(since = "6.0.5")
400-
default ByteBuffer toByteBuffer() {
401-
return toByteBuffer(readPosition(), readableByteCount());
402-
}
403-
404-
/**
405-
* Returns a {@link ByteBuffer} representation of a subsequence of this buffer's bytes. Data
406-
* between this {@code DataBuffer} and the returned {@code ByteBuffer} is <strong>not</strong>
407-
* shared.
408-
*
409-
* @return this data buffer as a byte buffer
410-
* @since 6.0
411-
* @see #readableByteBuffers()
412-
* @see #writableByteBuffers()
413-
* @deprecated as of 6.0.5, in favor of {@link #toByteBuffer(int, ByteBuffer, int, int)}
414-
*/
415-
@Deprecated(since = "6.0.5")
416-
ByteBuffer toByteBuffer(int index, int length);
417-
418293
/**
419294
* Copies this entire data buffer into the given destination {@code ByteBuffer}, beginning at the
420295
* current {@linkplain #readPosition() reading position}, and the current {@linkplain
@@ -442,7 +317,6 @@ default void toByteBuffer(ByteBuffer dest) {
442317

443318
/**
444319
* Returns a closeable iterator over each {@link ByteBuffer} in this data buffer that can be read.
445-
* Calling this method is more efficient than {@link #toByteBuffer()}, as no data is copied.
446320
* However, the byte buffers provided can only be used during the iteration.
447321
*
448322
* <p><b>Note</b> that the returned iterator must be used in a try-with-resources clause or

jooby/src/main/java/io/jooby/buffer/DataBufferFactory.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ public interface DataBufferFactory {
2323
* implementation and its configuration, this will be heap-based or direct buffer.
2424
*
2525
* @return the allocated buffer
26-
* @deprecated as of 6.0, in favor of {@link #allocateBuffer(int)}
2726
*/
28-
@Deprecated(since = "6.0")
2927
DataBuffer allocateBuffer();
3028

3129
/**

jooby/src/main/java/io/jooby/buffer/DataBufferWrapper.java

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,6 @@ public int capacity() {
6969
return this.delegate.capacity();
7070
}
7171

72-
@Override
73-
@Deprecated
74-
public DataBuffer capacity(int capacity) {
75-
return this.delegate.capacity(capacity);
76-
}
77-
78-
@Override
79-
@Deprecated
80-
public DataBuffer ensureCapacity(int capacity) {
81-
return this.delegate.ensureCapacity(capacity);
82-
}
83-
8472
@Override
8573
public DataBuffer ensureWritable(int capacity) {
8674
return this.delegate.ensureWritable(capacity);
@@ -156,47 +144,11 @@ public DataBuffer write(CharSequence charSequence, Charset charset) {
156144
return this.delegate.write(charSequence, charset);
157145
}
158146

159-
@Override
160-
@Deprecated
161-
public DataBuffer slice(int index, int length) {
162-
return this.delegate.slice(index, length);
163-
}
164-
165-
@Override
166-
@Deprecated
167-
public DataBuffer retainedSlice(int index, int length) {
168-
return this.delegate.retainedSlice(index, length);
169-
}
170-
171147
@Override
172148
public DataBuffer split(int index) {
173149
return this.delegate.split(index);
174150
}
175151

176-
@Override
177-
@Deprecated
178-
public ByteBuffer asByteBuffer() {
179-
return this.delegate.asByteBuffer();
180-
}
181-
182-
@Override
183-
@Deprecated
184-
public ByteBuffer asByteBuffer(int index, int length) {
185-
return this.delegate.asByteBuffer(index, length);
186-
}
187-
188-
@Override
189-
@Deprecated
190-
public ByteBuffer toByteBuffer() {
191-
return this.delegate.toByteBuffer();
192-
}
193-
194-
@Override
195-
@Deprecated
196-
public ByteBuffer toByteBuffer(int index, int length) {
197-
return this.delegate.toByteBuffer(index, length);
198-
}
199-
200152
@Override
201153
public void toByteBuffer(ByteBuffer dest) {
202154
this.delegate.toByteBuffer(dest);

jooby/src/main/java/io/jooby/buffer/DefaultDataBuffer.java

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,6 @@ public int capacity() {
167167
return this.capacity;
168168
}
169169

170-
@Override
171-
@Deprecated
172-
public DataBuffer capacity(int capacity) {
173-
setCapacity(capacity);
174-
return this;
175-
}
176-
177170
private void setCapacity(int newCapacity) {
178171
if (newCapacity < 0) {
179172
throw new IllegalArgumentException(
@@ -333,21 +326,6 @@ private void write(ByteBuffer source) {
333326
this.writePosition += length;
334327
}
335328

336-
@Override
337-
@Deprecated
338-
public DefaultDataBuffer slice(int index, int length) {
339-
checkIndex(index, length);
340-
int oldPosition = this.byteBuffer.position();
341-
try {
342-
this.byteBuffer.position(index);
343-
ByteBuffer slice = this.byteBuffer.slice();
344-
slice.limit(length);
345-
return new SlicedDefaultDataBuffer(slice, this.dataBufferFactory, length);
346-
} finally {
347-
this.byteBuffer.position(oldPosition);
348-
}
349-
}
350-
351329
@Override
352330
public DataBuffer split(int index) {
353331
checkIndex(index);
@@ -372,35 +350,6 @@ public DataBuffer split(int index) {
372350
return result;
373351
}
374352

375-
@Override
376-
@Deprecated
377-
public ByteBuffer asByteBuffer() {
378-
return asByteBuffer(this.readPosition, readableByteCount());
379-
}
380-
381-
@Override
382-
@Deprecated
383-
public ByteBuffer asByteBuffer(int index, int length) {
384-
checkIndex(index, length);
385-
386-
ByteBuffer duplicate = this.byteBuffer.duplicate();
387-
duplicate.position(index);
388-
duplicate.limit(index + length);
389-
return duplicate.slice();
390-
}
391-
392-
@Override
393-
@Deprecated
394-
public ByteBuffer toByteBuffer(int index, int length) {
395-
checkIndex(index, length);
396-
397-
ByteBuffer copy = allocate(length, this.byteBuffer.isDirect());
398-
ByteBuffer readOnly = this.byteBuffer.asReadOnlyBuffer();
399-
readOnly.clear().position(index).limit(index + length);
400-
copy.put(readOnly);
401-
return copy.flip();
402-
}
403-
404353
@Override
405354
public void toByteBuffer(int srcPos, ByteBuffer dest, int destPos, int length) {
406355
checkIndex(srcPos, length);
@@ -521,13 +470,6 @@ private static class SlicedDefaultDataBuffer extends DefaultDataBuffer {
521470
super(dataBufferFactory, byteBuffer);
522471
writePosition(length);
523472
}
524-
525-
@Override
526-
@SuppressWarnings("deprecation")
527-
public DefaultDataBuffer capacity(int newCapacity) {
528-
throw new UnsupportedOperationException(
529-
"Changing the capacity of a sliced buffer is not supported");
530-
}
531473
}
532474

533475
private static final class ByteBufferIterator implements DataBuffer.ByteBufferIterator {

jooby/src/main/java/io/jooby/buffer/DefaultDataBufferFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public DefaultDataBufferFactory(boolean preferDirect, int defaultInitialCapacity
7070
}
7171

7272
@Override
73-
@Deprecated
7473
public DefaultDataBuffer allocateBuffer() {
7574
return allocateBuffer(this.defaultInitialCapacity);
7675
}
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
/**
2-
* Generic abstraction for working with byte buffer implementations. Copy from
2+
* Generic abstraction for working with byte buffer implementations.
3+
*
4+
* <p>Copy from
35
* https://github.com/spring-projects/spring-framework/tree/main/spring-core/src/main/java/org/springframework/core/io/buffer.
4-
* - Copy all package inside io.jooby.byffer - remove all Assert/ObjectUtils import references -
5-
* remove Netty5DataBuffer references. - replace reactive stream classes references by JDK reactive
6-
* streams. - DataBufferUtils is a limited version of original - remove Deprecated methods
6+
*
7+
* <ul>
8+
* <li>Copy all package inside io.jooby.byffer
9+
* <li>remove all Assert/ObjectUtils import references
10+
* <li>remove Netty5DataBuffer references
11+
* <li>replace reactive stream classes references by JDK reactive streams
12+
* <li>DataBufferUtils is a limited version of original - remove Deprecated methods
13+
* <li>Remove all deprecated since 6.0 from DataBuffer and DataBufferFactory
14+
* </ul>
715
*/
816
package io.jooby.buffer;

modules/jooby-jackson/src/main/java/io/jooby/jackson/JacksonModule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.jooby.jackson;
77

88
import java.io.InputStream;
9+
import java.io.OutputStream;
910
import java.lang.reflect.Type;
1011
import java.nio.ByteBuffer;
1112
import java.util.HashMap;
@@ -155,6 +156,7 @@ public void install(@NonNull Jooby application) {
155156
@Override
156157
public ByteBuffer encode(@NonNull Context ctx, @NonNull Object value) throws Exception {
157158
ctx.setDefaultResponseType(mediaType);
159+
mapper.writer().writeValue(OutputStream.nullOutputStream(), value);
158160
return ByteBuffer.wrap(mapper.writer().writeValueAsBytes(value));
159161
}
160162

0 commit comments

Comments
 (0)