mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8129776: The optimized Stream returned from Files.lines should unmap the mapped byte buffer (if created) when closed
Reviewed-by: rriggs, psandoz, alanb
This commit is contained in:
parent
ad525bcd38
commit
7451962849
3 changed files with 50 additions and 18 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -4121,9 +4121,11 @@ public final class Files {
|
|||
// FileChannel.size() may in certain circumstances return zero
|
||||
// for a non-zero length file so disallow this case.
|
||||
if (length > 0 && length <= Integer.MAX_VALUE) {
|
||||
Spliterator<String> s = new FileChannelLinesSpliterator(fc, cs, 0, (int) length);
|
||||
return StreamSupport.stream(s, false)
|
||||
.onClose(Files.asUncheckedRunnable(fc));
|
||||
FileChannelLinesSpliterator fcls =
|
||||
new FileChannelLinesSpliterator(fc, cs, 0, (int) length);
|
||||
return StreamSupport.stream(fcls, false)
|
||||
.onClose(Files.asUncheckedRunnable(fc))
|
||||
.onClose(() -> fcls.close());
|
||||
}
|
||||
} catch (Error|RuntimeException|IOException e) {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue