Skip to content

Commit

Permalink
yegor256#254 - temp file removal and stream closure in RqMultipart
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Eliseev committed Jan 22, 2016
1 parent 9fed710 commit ca5b26b
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions src/main/java/org/takes/rq/RqMultipart.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,30 +235,35 @@ private Request make(final byte[] boundary) throws IOException {
final File file = File.createTempFile(
RqMultipart.class.getName(), ".tmp"
);
file.deleteOnExit();
final FileChannel channel = new RandomAccessFile(
file, "rw"
).getChannel();
try {
channel.write(
ByteBuffer.wrap(this.head().iterator().next().getBytes())
);
// @checkstyle MultipleStringLiteralsCheck (1 line)
channel.write(ByteBuffer.wrap("\r\n".getBytes()));
this.copy(channel, boundary);
final FileChannel channel = new RandomAccessFile(
file, "rw"
).getChannel();
try {
channel.write(
ByteBuffer.wrap(
this.head().iterator().next().getBytes()
)
);
// @checkstyle MultipleStringLiteralsCheck (1 line)
channel.write(ByteBuffer.wrap("\r\n".getBytes()));
this.copy(channel, boundary);
} finally {
channel.close();
}
final InputStream input = new FileInputStream(file);
try {
return new RqWithHeader(
new RqLive(new FileInputStream(file)),
"Content-Length",
String.valueOf(file.length())
);
} finally {
input.close();
}
} finally {
channel.close();
file.delete();
}
return new RqWithHeader(
new RqLive(
new CapInputStream(
new FileInputStream(file),
file.length()
)
),
"Content-Length",
String.valueOf(file.length())
);
}
/**
* Copy until boundary reached.
Expand Down

0 comments on commit ca5b26b

Please sign in to comment.