Skip to content

Commit

Permalink
🎨
Browse files Browse the repository at this point in the history
  • Loading branch information
TAKETODAY committed Dec 5, 2024
1 parent 51d52d9 commit eecf49f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
10 changes: 10 additions & 0 deletions today-core/src/main/java/infra/core/io/ResourceRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package infra.core.io;

import infra.core.style.ToStringBuilder;
import infra.lang.Assert;

/**
Expand Down Expand Up @@ -74,4 +75,13 @@ public long getCount() {
return this.count;
}

@Override
public String toString() {
return ToStringBuilder.forInstance(this)
.append("count", count)
.append("position", position)
.append("resource", resource)
.toString();
}

}
21 changes: 9 additions & 12 deletions today-web/src/main/java/infra/http/HttpRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @author TODAY 2021/11/6 23:43
* @author <a href="https://github.com/TAKETODAY">海子 Yang</a>
* @see <a href="https://tools.ietf.org/html/rfc7233">HTTP/1.1: Range Requests</a>
* @see HttpHeaders#setRange(Collection)
* @see HttpHeaders#getRange()
* @since 4.0
* @since 4.0 2021/11/6 23:43
*/
public abstract class HttpRange {

/** Maximum ranges per request. */
private static final int MAX_RANGES = 100;

private static final String BYTE_RANGE_PREFIX = "bytes=";

/**
Expand Down Expand Up @@ -246,19 +247,15 @@ private static class ByteRange extends HttpRange {
private final Long lastPos;

public ByteRange(long firstPos, @Nullable Long lastPos) {
assertPositions(firstPos, lastPos);
this.firstPos = firstPos;
this.lastPos = lastPos;
}

private void assertPositions(long firstBytePos, @Nullable Long lastBytePos) {
if (firstBytePos < 0) {
throw new IllegalArgumentException("Invalid first byte position: " + firstBytePos);
if (firstPos < 0) {
throw new IllegalArgumentException("Invalid first byte position: " + firstPos);
}
if (lastBytePos != null && lastBytePos < firstBytePos) {
if (lastPos != null && lastPos < firstPos) {
throw new IllegalArgumentException("firstBytePosition=%d should be less then or equal to lastBytePosition=%d"
.formatted(firstBytePos, lastBytePos));
.formatted(firstPos, lastPos));
}
this.firstPos = firstPos;
this.lastPos = lastPos;
}

@Override
Expand Down

0 comments on commit eecf49f

Please sign in to comment.