Skip to content

Commit 96e5e92

Browse files
committed
[GH-3193] Avoid deadlock in writeAllTo by removing WritableByteChannel usage
1 parent 66e0c4e commit 96e5e92

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

parquet-common/src/main/java/org/apache/parquet/bytes/ConcatenatingByteBufferCollector.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import java.io.IOException;
2424
import java.io.OutputStream;
2525
import java.nio.ByteBuffer;
26-
import java.nio.channels.Channels;
27-
import java.nio.channels.WritableByteChannel;
2826
import java.util.ArrayList;
2927
import java.util.List;
3028

@@ -72,9 +70,15 @@ public void close() {
7270

7371
@Override
7472
public void writeAllTo(OutputStream out) throws IOException {
75-
WritableByteChannel channel = Channels.newChannel(out);
7673
for (ByteBuffer buffer : slabs) {
77-
channel.write(buffer.duplicate());
74+
ByteBuffer dup = buffer.duplicate();
75+
if (dup.hasArray()) {
76+
out.write(dup.array(), dup.arrayOffset() + dup.position(), dup.remaining());
77+
} else {
78+
byte[] bytes = new byte[dup.remaining()];
79+
dup.get(bytes);
80+
out.write(bytes);
81+
}
7882
}
7983
}
8084

0 commit comments

Comments
 (0)