Browse Source

Deprecate TemporaryBuffer.LocalFile without parent directory

Encourage callers to explicitly name a directory to hold any
overflow data. Call sites have more information about what is
going into the buffer and how it should be protected at the
filesystem level than just throwing content to the system wide
temporary directory.

Callers that still really don't care (or need to care) can pass
null for the File argument to have the system directory used.

Change-Id: I89009bbee49d3850d42cd82c2c462e51043acda0
tags/v3.4.2.201412180340-r
Shawn Pearce 9 years ago
parent
commit
61b632ee5a

+ 1
- 1
org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java View File

buf.destroy(); buf.destroy();
} }
commitId = line.substring("commit ".length()); commitId = line.substring("commit ".length());
buf = new TemporaryBuffer.LocalFile();
buf = new TemporaryBuffer.LocalFile(null);
} else if (buf != null) { } else if (buf != null) {
buf.write(line.getBytes("ISO-8859-1")); buf.write(line.getBytes("ISO-8859-1"));
buf.write('\n'); buf.write('\n');

+ 12
- 12
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java View File

public class TemporaryBufferTest { public class TemporaryBufferTest {
@Test @Test
public void testEmpty() throws IOException { public void testEmpty() throws IOException {
final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
try { try {
b.close(); b.close();
assertEquals(0, b.length()); assertEquals(0, b.length());


@Test @Test
public void testOneByte() throws IOException { public void testOneByte() throws IOException {
final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte test = (byte) new TestRng(getName()).nextInt(); final byte test = (byte) new TestRng(getName()).nextInt();
try { try {
b.write(test); b.write(test);


@Test @Test
public void testOneBlock_BulkWrite() throws IOException { public void testOneBlock_BulkWrite() throws IOException {
final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName()) final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ); .nextBytes(TemporaryBuffer.Block.SZ);
try { try {


@Test @Test
public void testOneBlockAndHalf_BulkWrite() throws IOException { public void testOneBlockAndHalf_BulkWrite() throws IOException {
final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName()) final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2); .nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
try { try {


@Test @Test
public void testOneBlockAndHalf_SingleWrite() throws IOException { public void testOneBlockAndHalf_SingleWrite() throws IOException {
final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName()) final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2); .nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
try { try {


@Test @Test
public void testOneBlockAndHalf_Copy() throws IOException { public void testOneBlockAndHalf_Copy() throws IOException {
final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName()) final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2); .nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
try { try {


@Test @Test
public void testLarge_SingleWrite() throws IOException { public void testLarge_SingleWrite() throws IOException {
final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName()) final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3); .nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3);
try { try {


@Test @Test
public void testInCoreLimit_SwitchOnAppendByte() throws IOException { public void testInCoreLimit_SwitchOnAppendByte() throws IOException {
final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName()) final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT + 1); .nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT + 1);
try { try {


@Test @Test
public void testInCoreLimit_SwitchBeforeAppendByte() throws IOException { public void testInCoreLimit_SwitchBeforeAppendByte() throws IOException {
final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName()) final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3); .nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3);
try { try {


@Test @Test
public void testInCoreLimit_SwitchOnCopy() throws IOException { public void testInCoreLimit_SwitchOnCopy() throws IOException {
final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName()) final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2); .nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2);
try { try {
@Test @Test
public void testDestroyWhileOpen() throws IOException { public void testDestroyWhileOpen() throws IOException {
@SuppressWarnings("resource" /* java 7 */) @SuppressWarnings("resource" /* java 7 */)
final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
try { try {
b.write(new TestRng(getName()) b.write(new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2)); .nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2));


@Test @Test
public void testRandomWrites() throws IOException { public void testRandomWrites() throws IOException {
final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final TestRng rng = new TestRng(getName()); final TestRng rng = new TestRng(getName());
final int max = TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2; final int max = TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2;
final byte[] expect = new byte[max]; final byte[] expect = new byte[max];

+ 8
- 1
org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java View File

*/ */
private File onDiskFile; private File onDiskFile;


/** Create a new temporary buffer. */
/**
* Create a new temporary buffer.
*
* @deprecated Use the {@code File} overload to supply a directory.
*/
@Deprecated
public LocalFile() { public LocalFile() {
this(null, DEFAULT_IN_CORE_LIMIT); this(null, DEFAULT_IN_CORE_LIMIT);
} }
* @param inCoreLimit * @param inCoreLimit
* maximum number of bytes to store in memory. Storage beyond * maximum number of bytes to store in memory. Storage beyond
* this limit will use the local file. * this limit will use the local file.
* @deprecated Use the {@code File,int} overload to supply a directory.
*/ */
@Deprecated
public LocalFile(final int inCoreLimit) { public LocalFile(final int inCoreLimit) {
this(null, inCoreLimit); this(null, inCoreLimit);
} }

Loading…
Cancel
Save