Fix incorrect usage of StringBuilder#append in TransactionAwareBufferedWriter
Issue #3745
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
e176058d3e
commit
f7e6eabd17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2020 the original author or authors.
|
||||
* Copyright 2006-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,6 +33,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Michael Minella
|
||||
* @author Niels Ferguson
|
||||
*
|
||||
*/
|
||||
public class TransactionAwareBufferedWriter extends Writer {
|
||||
@@ -244,6 +245,6 @@ public class TransactionAwareBufferedWriter extends Writer {
|
||||
}
|
||||
|
||||
StringBuilder buffer = getCurrentBuffer();
|
||||
buffer.append(str, off, len);
|
||||
buffer.append(str, off, off + len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2012 the original author or authors.
|
||||
* Copyright 2006-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,6 +40,7 @@ import static org.mockito.Mockito.when;
|
||||
* @author Dave Syer
|
||||
* @author Michael Minella
|
||||
* @author Will Schipp
|
||||
* @author Niels Ferguson
|
||||
*
|
||||
*/
|
||||
public class TransactionAwareBufferedWriterTests {
|
||||
@@ -337,6 +338,27 @@ public class TransactionAwareBufferedWriterTests {
|
||||
}
|
||||
}
|
||||
|
||||
//BATCH-3745
|
||||
@Test
|
||||
public void testWriteInTransactionWithOffset() throws IOException{
|
||||
ArgumentCaptor<ByteBuffer> bb = ArgumentCaptor.forClass(ByteBuffer.class);
|
||||
when(fileChannel.write(bb.capture())).thenReturn(3);
|
||||
|
||||
new TransactionTemplate(transactionManager).execute((TransactionCallback<Void>) status -> {
|
||||
|
||||
try {
|
||||
writer.write("hamburger", 4, 3);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Unexpected IOException", e);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
String s = getStringFromByteBuffer(bb.getValue());
|
||||
|
||||
assertEquals("urg", s);
|
||||
}
|
||||
|
||||
private String getStringFromByteBuffer(ByteBuffer bb) {
|
||||
byte[] bytearr = new byte[bb.remaining()];
|
||||
bb.get(bytearr);
|
||||
|
||||
Reference in New Issue
Block a user