Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit fe71df4

Browse files
committed
Merge branch 'v1.6.2'
2 parents 1c00ba1 + 25a4cf8 commit fe71df4

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</parent>
1010
<groupId>lee.study</groupId>
1111
<artifactId>proxyee-down</artifactId>
12-
<version>1.6.1</version>
12+
<version>1.6.2</version>
1313

1414
<build>
1515
<plugins>

src/main/java/lee/study/down/ext/LargeMappedByteBuffer.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@
99
import java.nio.channels.FileChannel.MapMode;
1010
import java.util.LinkedList;
1111
import java.util.List;
12-
import org.slf4j.Logger;
13-
import org.slf4j.LoggerFactory;
14-
import sun.nio.ch.FileChannelImpl;
1512

1613
public class LargeMappedByteBuffer implements Closeable {
1714

18-
private static final Logger LOGGER = LoggerFactory.getLogger(LargeMappedByteBuffer.class);
19-
2015
private List<MappedByteBuffer> bufferList;
2116
private long rawPosition;
2217
private long position;
18+
private long size;
2319

2420
public LargeMappedByteBuffer(FileChannel fileChannel, MapMode mapMode, long position, long size)
2521
throws IOException {
2622
this.rawPosition = position;
2723
this.position = position;
24+
this.size = size;
2825
int count = (int) Math.ceil(size / (double) Integer.MAX_VALUE);
2926
this.bufferList = new LinkedList<>();
3027
long calcPos = position;
@@ -35,18 +32,22 @@ public LargeMappedByteBuffer(FileChannel fileChannel, MapMode mapMode, long posi
3532
}
3633
}
3734

38-
public final void put(ByteBuffer byteBuffer) {
39-
int index = getIndex();
40-
long length = byteBuffer.limit() - byteBuffer.position();
41-
this.position += length;
42-
MappedByteBuffer mappedBuffer = bufferList.get(index);
43-
if (mappedBuffer.remaining() < length) {
44-
byte[] temp = new byte[mappedBuffer.remaining()];
45-
byteBuffer.get(temp);
46-
bufferList.get(index).put(temp);
47-
bufferList.get(index + 1).put(byteBuffer);
48-
} else {
49-
bufferList.get(index).put(byteBuffer);
35+
public final void put(ByteBuffer byteBuffer) throws IOException {
36+
try {
37+
int index = getIndex();
38+
long length = byteBuffer.limit() - byteBuffer.position();
39+
this.position += length;
40+
MappedByteBuffer mappedBuffer = bufferList.get(index);
41+
if (mappedBuffer.remaining() < length) {
42+
byte[] temp = new byte[mappedBuffer.remaining()];
43+
byteBuffer.get(temp);
44+
bufferList.get(index).put(temp);
45+
bufferList.get(index + 1).put(byteBuffer);
46+
} else {
47+
bufferList.get(index).put(byteBuffer);
48+
}
49+
} catch (Exception e) {
50+
throw new IOException("LargeMappedByteBuffer put rawPosition-"+rawPosition+" size-"+size, e);
5051
}
5152
}
5253

@@ -57,13 +58,14 @@ private int getIndex() {
5758
@Override
5859
public void close() throws IOException {
5960
try {
60-
Method m = FileChannelImpl.class.getDeclaredMethod("unmap", MappedByteBuffer.class);
61+
Class<?> clazz = Class.forName("sun.nio.ch.FileChannelImpl");
62+
Method m = clazz.getDeclaredMethod("unmap", MappedByteBuffer.class);
6163
m.setAccessible(true);
6264
for (MappedByteBuffer mappedBuffer : bufferList) {
63-
m.invoke(FileChannelImpl.class, mappedBuffer);
65+
m.invoke(clazz, mappedBuffer);
6466
}
6567
} catch (Exception e) {
66-
LOGGER.error("LargeMappedByteBuffer close:",e);
68+
throw new IOException("LargeMappedByteBuffer close", e);
6769
}
6870
}
6971

src/main/java/lee/study/down/hanndle/HttpDownInitializer.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
148148
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
149149
callback.onError(taskInfo, chunkInfo, cause);
150150
if (cause instanceof IOException) {
151-
HttpDownServer.LOGGER.debug(
152-
"服务器响应异常重试:" + chunkInfo.getIndex() + "\t" + chunkInfo.getDownSize());
153-
} else {
154151
HttpDownServer.LOGGER.error("down onError:", cause);
155152
}
156153
}

0 commit comments

Comments
 (0)