Skip to content

Commit cf8c7fd

Browse files
Apply spotless
1 parent 0848545 commit cf8c7fd

File tree

11 files changed

+344
-303
lines changed

11 files changed

+344
-303
lines changed

x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/BufferOnMarkInputStream.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ public long skip(long n) throws IOException {
188188
return source.skip(n);
189189
}
190190
long remaining = n;
191-
int size = (int)Math.min(2048, remaining);
191+
int size = (int) Math.min(2048, remaining);
192192
byte[] skipBuffer = new byte[size];
193193
while (remaining > 0) {
194194
// skipping translates to a read so that the skipped bytes are stored in the buffer,
195195
// so they can possibly be replayed after a reset
196-
int bytesRead = read(skipBuffer, 0, (int)Math.min(size, remaining));
196+
int bytesRead = read(skipBuffer, 0, (int) Math.min(size, remaining));
197197
if (bytesRead < 0) {
198198
break;
199199
}
@@ -261,8 +261,9 @@ public void mark(int readlimit) {
261261
// readlimit is otherwise ignored but this defensively fails if the caller is expecting to be able to mark/reset more than this
262262
// instance can accommodate in the fixed ring buffer
263263
if (readlimit > ringBuffer.getBufferSize()) {
264-
throw new IllegalArgumentException("Readlimit value [" + readlimit + "] exceeds the maximum value of [" +
265-
ringBuffer.getBufferSize() + "]");
264+
throw new IllegalArgumentException(
265+
"Readlimit value [" + readlimit + "] exceeds the maximum value of [" + ringBuffer.getBufferSize() + "]"
266+
);
266267
} else if (readlimit < 0) {
267268
throw new IllegalArgumentException("Readlimit value [" + readlimit + "] cannot be negative");
268269
}

x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/ChainingInputStream.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ public int read() throws IOException {
125125
return -1;
126126
}
127127

128-
129128
/**
130129
* Reads up to {@code len} bytes of data into an array of bytes from this
131130
* chaining input stream. If {@code len} is zero, then no bytes are read

x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/DecryptionPacketsInputStream.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ InputStream nextComponent(InputStream currentComponentIn) throws IOException {
9898
if (false == hasNext) {
9999
return null;
100100
}
101-
PrefixInputStream packetInputStream = new PrefixInputStream(source,
102-
packetLength + GCM_IV_LENGTH_IN_BYTES + GCM_TAG_LENGTH_IN_BYTES,
103-
false);
101+
PrefixInputStream packetInputStream = new PrefixInputStream(
102+
source,
103+
packetLength + GCM_IV_LENGTH_IN_BYTES + GCM_TAG_LENGTH_IN_BYTES,
104+
false
105+
);
104106
int currentPacketLength = decrypt(packetInputStream);
105107
// only the last packet is shorter, so this must be the last packet
106108
if (currentPacketLength != packetLength) {
@@ -115,8 +117,7 @@ public boolean markSupported() {
115117
}
116118

117119
@Override
118-
public void mark(int readlimit) {
119-
}
120+
public void mark(int readlimit) {}
120121

121122
@Override
122123
public void reset() throws IOException {

x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/EncryptedRepositoryPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
public final class EncryptedRepositoryPlugin extends Plugin implements RepositoryPlugin, ReloadablePlugin {
1818

19-
public EncryptedRepositoryPlugin(final Settings settings) {
20-
}
19+
public EncryptedRepositoryPlugin(final Settings settings) {}
2120

2221
@Override
2322
public List<Setting<?>> getSettings() {

x-pack/plugin/repository-encrypted/src/main/java/org/elasticsearch/repositories/encrypted/EncryptionPacketsInputStream.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public final class EncryptionPacketsInputStream extends ChainingInputStream {
8787
*/
8888
public static long getEncryptionLength(long plaintextLength, int packetLength) {
8989
return plaintextLength + (plaintextLength / packetLength + 1) * (EncryptedRepository.GCM_TAG_LENGTH_IN_BYTES
90-
+ EncryptedRepository.GCM_IV_LENGTH_IN_BYTES);
90+
+ EncryptedRepository.GCM_IV_LENGTH_IN_BYTES);
9191
}
9292

9393
public EncryptionPacketsInputStream(InputStream source, SecretKey secretKey, int nonce, int packetLength) {
@@ -100,8 +100,8 @@ public EncryptionPacketsInputStream(InputStream source, SecretKey secretKey, int
100100
this.packetIv = ByteBuffer.allocate(EncryptedRepository.GCM_IV_LENGTH_IN_BYTES).order(ByteOrder.LITTLE_ENDIAN);
101101
// nonce takes the first 4 bytes of the IV
102102
this.packetIv.putInt(0, nonce);
103-
this.encryptedPacketLength =
104-
packetLength + EncryptedRepository.GCM_IV_LENGTH_IN_BYTES + EncryptedRepository.GCM_TAG_LENGTH_IN_BYTES;
103+
this.encryptedPacketLength = packetLength + EncryptedRepository.GCM_IV_LENGTH_IN_BYTES
104+
+ EncryptedRepository.GCM_TAG_LENGTH_IN_BYTES;
105105
this.counter = EncryptedRepository.PACKET_START_COUNTER;
106106
this.markCounter = null;
107107
this.markSourceOnNextPacket = -1;

x-pack/plugin/repository-encrypted/src/test/java/org/elasticsearch/repositories/encrypted/BufferOnMarkInputStreamTests.java

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public void testResetWithoutMarkFails() throws Exception {
4040
BufferOnMarkInputStream test = new BufferOnMarkInputStream(mockSourceTuple.v2(), 1 + Randomness.get().nextInt(1024));
4141
// maybe read some bytes
4242
test.readNBytes(randomFrom(0, randomInt(31)));
43-
IOException e = expectThrows(IOException.class, () -> {
44-
test.reset();
45-
});
43+
IOException e = expectThrows(IOException.class, () -> { test.reset(); });
4644
assertThat(e.getMessage(), Matchers.is("Mark not called or has been invalidated"));
4745
}
4846

@@ -54,18 +52,14 @@ public void testMarkAndBufferReadLimitsCheck() throws Exception {
5452
// maybe read some bytes
5553
test.readNBytes(randomFrom(0, randomInt(32)));
5654
int wrongLargeReadLimit = bufferSize + randomIntBetween(1, 8);
57-
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
58-
test.mark(wrongLargeReadLimit);
59-
});
60-
assertThat(e.getMessage(), Matchers.is("Readlimit value [" + wrongLargeReadLimit + "] exceeds the maximum value of ["
61-
+ bufferSize + "]"));
62-
e = expectThrows(IllegalArgumentException.class, () -> {
63-
test.mark(-1 - randomInt(1));
64-
});
55+
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> { test.mark(wrongLargeReadLimit); });
56+
assertThat(
57+
e.getMessage(),
58+
Matchers.is("Readlimit value [" + wrongLargeReadLimit + "] exceeds the maximum value of [" + bufferSize + "]")
59+
);
60+
e = expectThrows(IllegalArgumentException.class, () -> { test.mark(-1 - randomInt(1)); });
6561
assertThat(e.getMessage(), Matchers.containsString("cannot be negative"));
66-
e = expectThrows(IllegalArgumentException.class, () -> {
67-
new BufferOnMarkInputStream(mock(InputStream.class), 0 - randomInt(1));
68-
});
62+
e = expectThrows(IllegalArgumentException.class, () -> { new BufferOnMarkInputStream(mock(InputStream.class), 0 - randomInt(1)); });
6963
assertThat(e.getMessage(), Matchers.is("The buffersize constructor argument must be a strictly positive value"));
7064
}
7165

@@ -78,26 +72,18 @@ public void testCloseRejectsSuccessiveCalls() throws Exception {
7872
test.readNBytes(randomFrom(0, Randomness.get().nextInt(32)));
7973
test.close();
8074
int bytesReadBefore = bytesRead.get();
81-
IOException e = expectThrows(IOException.class, () -> {
82-
test.read();
83-
});
75+
IOException e = expectThrows(IOException.class, () -> { test.read(); });
8476
assertThat(e.getMessage(), Matchers.is("Stream has been closed"));
8577
e = expectThrows(IOException.class, () -> {
8678
byte[] b = new byte[1 + Randomness.get().nextInt(32)];
8779
test.read(b, 0, 1 + Randomness.get().nextInt(b.length));
8880
});
8981
assertThat(e.getMessage(), Matchers.is("Stream has been closed"));
90-
e = expectThrows(IOException.class, () -> {
91-
test.skip(1 + Randomness.get().nextInt(32));
92-
});
82+
e = expectThrows(IOException.class, () -> { test.skip(1 + Randomness.get().nextInt(32)); });
9383
assertThat(e.getMessage(), Matchers.is("Stream has been closed"));
94-
e = expectThrows(IOException.class, () -> {
95-
test.available();
96-
});
84+
e = expectThrows(IOException.class, () -> { test.available(); });
9785
assertThat(e.getMessage(), Matchers.is("Stream has been closed"));
98-
e = expectThrows(IOException.class, () -> {
99-
test.reset();
100-
});
86+
e = expectThrows(IOException.class, () -> { test.reset(); });
10187
assertThat(e.getMessage(), Matchers.is("Stream has been closed"));
10288
int bytesReadAfter = bytesRead.get();
10389
assertThat(bytesReadAfter - bytesReadBefore, Matchers.is(0));
@@ -216,9 +202,7 @@ public void testMarkInvalidation() throws Exception {
216202
assertThat(test.storeToBuffer, Matchers.is(false));
217203
assertThat(test.replayFromBuffer, Matchers.is(false));
218204
// assert reset does not work any more
219-
IOException e = expectThrows(IOException.class, () -> {
220-
test.reset();
221-
});
205+
IOException e = expectThrows(IOException.class, () -> { test.reset(); });
222206
assertThat(e.getMessage(), Matchers.is("Mark not called or has been invalidated"));
223207
}
224208

@@ -356,9 +340,7 @@ public void testInvalidateMarkAfterReset() throws Exception {
356340
assertThat(test.storeToBuffer, Matchers.is(false));
357341
assertThat(test.replayFromBuffer, Matchers.is(false));
358342
// assert reset does not work anymore
359-
IOException e = expectThrows(IOException.class, () -> {
360-
test.reset();
361-
});
343+
IOException e = expectThrows(IOException.class, () -> { test.reset(); });
362344
assertThat(e.getMessage(), Matchers.is("Mark not called or has been invalidated"));
363345
}
364346

@@ -572,8 +554,9 @@ public void testNoMockSimpleMarkResetEverywhere() throws Exception {
572554
for (int length = 1; length <= 10; length++) {
573555
for (int offset = 0; offset < length; offset++) {
574556
for (int mark = 1; mark <= length - offset; mark++) {
575-
try (BufferOnMarkInputStream in = new BufferOnMarkInputStream(new
576-
NoMarkByteArrayInputStream(testArray, 0, length), mark)) {
557+
try (
558+
BufferOnMarkInputStream in = new BufferOnMarkInputStream(new NoMarkByteArrayInputStream(testArray, 0, length), mark)
559+
) {
577560
// skip first offset bytes
578561
in.readNBytes(offset);
579562
in.mark(mark);
@@ -595,8 +578,9 @@ public void testNoMockSimpleMarkResetEverywhere() throws Exception {
595578
public void testNoMockMarkResetEverywhere() throws Exception {
596579
for (int length = 1; length <= 8; length++) {
597580
for (int offset = 0; offset < length; offset++) {
598-
try (BufferOnMarkInputStream in = new BufferOnMarkInputStream(new NoMarkByteArrayInputStream(testArray, 0, length),
599-
length)) {
581+
try (
582+
BufferOnMarkInputStream in = new BufferOnMarkInputStream(new NoMarkByteArrayInputStream(testArray, 0, length), length)
583+
) {
600584
// skip first offset bytes
601585
in.readNBytes(offset);
602586
in.mark(length);
@@ -607,8 +591,9 @@ public void testNoMockMarkResetEverywhere() throws Exception {
607591
in.reset();
608592
}
609593
}
610-
try (BufferOnMarkInputStream in = new BufferOnMarkInputStream(new NoMarkByteArrayInputStream(testArray, 0, length),
611-
length)) {
594+
try (
595+
BufferOnMarkInputStream in = new BufferOnMarkInputStream(new NoMarkByteArrayInputStream(testArray, 0, length), length)
596+
) {
612597
// skip first offset bytes
613598
in.readNBytes(offset);
614599
in.mark(length);
@@ -628,8 +613,12 @@ public void testNoMockDoubleMarkEverywhere() throws Exception {
628613
for (int offset = 0; offset < length; offset++) {
629614
for (int readLen = 1; readLen <= length - offset; readLen++) {
630615
for (int markLen = 1; markLen <= length - offset; markLen++) {
631-
try (BufferOnMarkInputStream in = new BufferOnMarkInputStream(new NoMarkByteArrayInputStream(testArray, 0, length),
632-
length)) {
616+
try (
617+
BufferOnMarkInputStream in = new BufferOnMarkInputStream(
618+
new NoMarkByteArrayInputStream(testArray, 0, length),
619+
length
620+
)
621+
) {
633622
in.readNBytes(offset);
634623
assertThat(in.ringBuffer.getAvailableToWriteByteCount(), Matchers.is(length));
635624
assertThat(in.ringBuffer.getAvailableToReadByteCount(), Matchers.is(0));
@@ -719,7 +708,7 @@ private void testMarkResetMarkStep(BufferOnMarkInputStream stream, int offset, i
719708
stream.mark(stepLen);
720709
for (int readLen = 1; readLen <= Math.min(stepLen, length - offset); readLen++) {
721710
for (int markLen = 1; markLen <= Math.min(stepLen, length - offset); markLen++) {
722-
BufferOnMarkInputStream cloneStream = cloneBufferOnMarkStream(stream) ;
711+
BufferOnMarkInputStream cloneStream = cloneBufferOnMarkStream(stream);
723712
// read ahead
724713
byte[] test = cloneStream.readNBytes(readLen);
725714
assertArray(offset, test);
@@ -738,8 +727,10 @@ private void testMarkResetMarkStep(BufferOnMarkInputStream stream, int offset, i
738727
private BufferOnMarkInputStream cloneBufferOnMarkStream(BufferOnMarkInputStream orig) {
739728
int origOffset = ((NoMarkByteArrayInputStream) orig.source).getPos();
740729
int origLen = ((NoMarkByteArrayInputStream) orig.source).getCount();
741-
BufferOnMarkInputStream cloneStream = new BufferOnMarkInputStream(new NoMarkByteArrayInputStream(testArray,
742-
origOffset, origLen - origOffset), orig.ringBuffer.getBufferSize());
730+
BufferOnMarkInputStream cloneStream = new BufferOnMarkInputStream(
731+
new NoMarkByteArrayInputStream(testArray, origOffset, origLen - origOffset),
732+
orig.ringBuffer.getBufferSize()
733+
);
743734
if (orig.ringBuffer.buffer != null) {
744735
cloneStream.ringBuffer.buffer = Arrays.copyOf(orig.ringBuffer.buffer, orig.ringBuffer.buffer.length);
745736
} else {
@@ -777,17 +768,18 @@ private void assertArray(int offset, byte[] test) {
777768
private Tuple<AtomicInteger, InputStream> getMockInfiniteInputStream() throws IOException {
778769
InputStream mockSource = mock(InputStream.class);
779770
AtomicInteger bytesRead = new AtomicInteger(0);
780-
when(mockSource.read(org.mockito.Matchers.<byte[]>any(), org.mockito.Matchers.anyInt(), org.mockito.Matchers.anyInt())).
781-
thenAnswer(invocationOnMock -> {
782-
final int len = (int) invocationOnMock.getArguments()[2];
783-
if (len == 0) {
784-
return 0;
785-
} else {
786-
int bytesCount = 1 + Randomness.get().nextInt(len);
787-
bytesRead.addAndGet(bytesCount);
788-
return bytesCount;
789-
}
790-
});
771+
when(mockSource.read(org.mockito.Matchers.<byte[]>any(), org.mockito.Matchers.anyInt(), org.mockito.Matchers.anyInt())).thenAnswer(
772+
invocationOnMock -> {
773+
final int len = (int) invocationOnMock.getArguments()[2];
774+
if (len == 0) {
775+
return 0;
776+
} else {
777+
int bytesCount = 1 + Randomness.get().nextInt(len);
778+
bytesRead.addAndGet(bytesCount);
779+
return bytesCount;
780+
}
781+
}
782+
);
791783
when(mockSource.read()).thenAnswer(invocationOnMock -> {
792784
bytesRead.incrementAndGet();
793785
return Randomness.get().nextInt(256);
@@ -845,8 +837,7 @@ int getCount() {
845837
}
846838

847839
@Override
848-
public void mark(int readlimit) {
849-
}
840+
public void mark(int readlimit) {}
850841

851842
@Override
852843
public boolean markSupported() {

0 commit comments

Comments
 (0)