Skip to content

Commit f8547a5

Browse files
author
lorenzo
committed
Fixed default read strategy performances.
1 parent c56df7a commit f8547a5

File tree

6 files changed

+31
-18
lines changed

6 files changed

+31
-18
lines changed

releases.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[
2+
{
3+
"version": "1.0.1",
4+
"date": "//TODO: Add date",
5+
"release-notes": "<ul><li>Bugfix: Fixed default read strategy.</li><li>Bugfix: Changed default read buffer size for stream base strategies to 1048576 bytes.</li><ul>"
6+
},
27
{
38
"version": "1.0.0",
49
"date": "22/6/2020",

src/main/java/com/reedelk/file/component/FileReadConfiguration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import static org.osgi.service.component.annotations.ServiceScope.PROTOTYPE;
88

9-
@Collapsible
109
@Component(service = FileReadConfiguration.class, scope = PROTOTYPE)
1110
public class FileReadConfiguration implements Implementor {
1211

@@ -33,13 +32,14 @@ public class FileReadConfiguration implements Implementor {
3332
private Long lockRetryWaitTime;
3433

3534
@Property("Read buffer size")
36-
@Hint("65536")
37-
@Example("262144")
38-
@DefaultValue("65536")
35+
@Hint("524288")
36+
@Example("524288")
37+
@DefaultValue("1048576")
3938
@Description("The buffer size used to read the files from filesystem. " +
4039
"This parameter can be used to improve read performances. " +
4140
"If the files are big the buffer size should be bigger, " +
42-
"otherwise for very small files it should be kept smaller.")
41+
"otherwise for very small files it should be kept smaller. " +
42+
"The read buffer size is expressed in bytes and it can only be applied when the read mode strategy is 'Stream'.")
4343
private Integer readBufferSize;
4444

4545
public Boolean getLockFile() {

src/main/java/com/reedelk/file/internal/commons/Defaults.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class FileRead {
77
private FileRead() {
88
}
99

10-
public static final int READ_FILE_BUFFER_SIZE = 65536;
10+
public static final int READ_FILE_BUFFER_SIZE = 1048576;
1111
public static final int RETRY_MAX_ATTEMPTS = 3;
1212
public static final long RETRY_WAIT_TIME = 500;
1313
}
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
package com.reedelk.file.internal.read;
22

3-
import com.reedelk.runtime.api.commons.StreamUtils;
3+
import com.reedelk.file.internal.exception.FileReadException;
44
import org.reactivestreams.Publisher;
55
import reactor.core.publisher.Mono;
66

7+
import java.io.IOException;
8+
import java.nio.file.Files;
79
import java.nio.file.Path;
810

9-
public class ReadStrategyDefault extends ReadStrategyStream {
11+
import static com.reedelk.file.internal.commons.Messages.FileRead.FILE_READ_ERROR;
12+
13+
public class ReadStrategyDefault implements ReadStrategy {
1014

1115
@Override
1216
public Publisher<byte[]> read(Path path, ReadConfigurationDecorator config) {
13-
14-
Publisher<byte[]> read = super.read(path, config);
15-
16-
// We immediately consume the content.
17-
byte[] consume = StreamUtils.FromByteArray.consume(read);
18-
19-
return Mono.just(consume);
17+
try {
18+
byte[] bytes = Files.readAllBytes(path);
19+
return Mono.just(bytes);
20+
} catch (IOException e) {
21+
String message = FILE_READ_ERROR.format(path, e.getMessage());
22+
throw new FileReadException(message, e);
23+
}
2024
}
2125
}

src/main/java/com/reedelk/file/internal/read/ReadStrategyStream.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ public Publisher<byte[]> read(Path path, ReadConfigurationDecorator config) {
6262

6363
byteBuffer.get(chunk);
6464

65-
byteBuffer.clear();
66-
6765
sink.next(chunk);
66+
67+
byteBuffer.clear();
6868
}
6969

70+
byteBuffer.clear();
71+
72+
byteBuffer = null;
73+
7074
sink.complete();
7175

7276
} catch (NoSuchFileException exception) {

src/main/resources/module-descriptor.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)