Skip to content

Commit

Permalink
#651: Renamed RqMultipartX to RqMtX
Browse files Browse the repository at this point in the history
  • Loading branch information
essobedo committed Apr 20, 2016
1 parent 10eea12 commit 427ec70
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 123 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/takes/facets/forward/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* @Override
* public Response act(final Request req) {
* final InputStream content =
* new RqMultipart.Base(req).part("file").body();
* new RqMtBase(req).part("file").body();
* // save content to whenever you want
* return new RsForward(new RqHref(req).href());
* }
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/rq/RqForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* {@code application/x-www-form-urlencoded} format (RFC 1738).
*
* <p>For {@code multipart/form-data} format use
* {@link org.takes.rq.RqMultipart.Base}.
* {@link org.takes.rq.multipart.RqMtBase}.
*
* <p>It is highly recommended to use {@link org.takes.rq.RqGreedy}
* decorator before passing request to this class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
*/
@SuppressWarnings("PMD.ExcessiveImports")
@EqualsAndHashCode(of = "origin")
public final class RqMultipartBase implements RqMultipart {
public final class RqMtBase implements RqMultipart {
/**
* Pattern to get boundary from header.
*/
Expand Down Expand Up @@ -123,7 +123,7 @@ public final class RqMultipartBase implements RqMultipart {
* @throws IOException If fails
* @checkstyle ExecutableStatementCountCheck (2 lines)
*/
public RqMultipartBase(final Request req) throws IOException {
public RqMtBase(final Request req) throws IOException {
this.origin = req;
this.stream = new RqLengthAware(req).body();
this.buffer = ByteBuffer.allocate(
Expand Down Expand Up @@ -188,12 +188,12 @@ private Map<String, List<Request>> requests(
HttpURLConnection.HTTP_BAD_REQUEST,
String.format(
// @checkstyle LineLength (1 line)
"RqMultipart.Base can only parse multipart/form-data, while Content-Type specifies a different type: \"%s\"",
"RqMtBase can only parse multipart/form-data, while Content-Type specifies a different type: \"%s\"",
header
)
);
}
final Matcher matcher = RqMultipartBase.BOUNDARY.matcher(header);
final Matcher matcher = RqMtBase.BOUNDARY.matcher(header);
if (!matcher.matches()) {
throw new HttpException(
HttpURLConnection.HTTP_BAD_REQUEST,
Expand All @@ -211,7 +211,7 @@ private Map<String, List<Request>> requests(
);
}
final byte[] boundary = String.format(
"%s--%s", RqMultipartBase.CRLF, matcher.group(1)
"%s--%s", RqMtBase.CRLF, matcher.group(1)
).getBytes(StandardCharsets.UTF_8);
this.buffer.flip();
this.buffer.position(boundary.length - 2);
Expand All @@ -224,7 +224,7 @@ private Map<String, List<Request>> requests(
this.buffer.position(this.buffer.position() + 1);
requests.add(this.make(boundary, body));
}
return RqMultipartBase.asMap(requests);
return RqMtBase.asMap(requests);
}
/**
* Make a request.
Expand Down Expand Up @@ -253,7 +253,7 @@ private Request make(final byte[] boundary,
);
channel.write(
ByteBuffer.wrap(
RqMultipartBase.CRLF.getBytes(StandardCharsets.UTF_8)
RqMtBase.CRLF.getBytes(StandardCharsets.UTF_8)
)
);
this.copy(channel, boundary, body);
Expand Down Expand Up @@ -331,7 +331,7 @@ private static Map<String, List<Request>> asMap(
final String header = new RqHeaders.Smart(
new RqHeaders.Base(req)
).single("Content-Disposition");
final Matcher matcher = RqMultipartBase.NAME.matcher(header);
final Matcher matcher = RqMtBase.NAME.matcher(header);
if (!matcher.matches()) {
throw new HttpException(
HttpURLConnection.HTTP_BAD_REQUEST,
Expand Down Expand Up @@ -369,7 +369,7 @@ public void close() throws IOException {
super.close();
} finally {
for (final List<Request> requests
: RqMultipartBase.this.map.values()) {
: RqMtBase.this.map.values()) {
for (final Request request : requests) {
request.body().close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @version $Id$
* @since 0.33
*/
public final class RqMultipartFake implements RqMultipart {
public final class RqMtFake implements RqMultipart {
/**
* Fake boundary constant.
*/
Expand All @@ -58,10 +58,10 @@ public final class RqMultipartFake implements RqMultipart {
* @param dispositions Fake request body parts
* @throws IOException If fails
*/
public RqMultipartFake(final Request req, final Request... dispositions)
public RqMtFake(final Request req, final Request... dispositions)
throws IOException {
this.fake = new RqMultipartBase(
new RqMultipartFake.FakeMultipartRequest(req, dispositions)
this.fake = new RqMtBase(
new RqMtFake.FakeMultipartRequest(req, dispositions)
);
}
@Override
Expand Down Expand Up @@ -95,24 +95,24 @@ private static StringBuilder fakeBody(final Request... parts)
throws IOException {
final StringBuilder builder = new StringBuilder();
for (final Request part : parts) {
builder.append(String.format("--%s", RqMultipartFake.BOUNDARY))
.append(RqMultipartFake.CRLF)
builder.append(String.format("--%s", RqMtFake.BOUNDARY))
.append(RqMtFake.CRLF)
.append("Content-Disposition: ")
.append(
new RqHeaders.Smart(
new RqHeaders.Base(part)
).single("Content-Disposition")
).append(RqMultipartFake.CRLF);
).append(RqMtFake.CRLF);
final String body = new RqPrint(part).printBody();
if (!(RqMultipartFake.CRLF.equals(body) || body.isEmpty())) {
builder.append(RqMultipartFake.CRLF)
if (!(RqMtFake.CRLF.equals(body) || body.isEmpty())) {
builder.append(RqMtFake.CRLF)
.append(body)
.append(RqMultipartFake.CRLF);
.append(RqMtFake.CRLF);
}
}
builder.append("Content-Transfer-Encoding: utf-8")
.append(RqMultipartFake.CRLF)
.append(String.format("--%s--", RqMultipartFake.BOUNDARY));
.append(RqMtFake.CRLF)
.append(String.format("--%s--", RqMtFake.BOUNDARY));
return builder;
}

Expand All @@ -138,15 +138,15 @@ private static final class FakeMultipartRequest implements Request {
FakeMultipartRequest(final Request rqst, final Request... list)
throws IOException {
this.req = rqst;
this.parts = RqMultipartFake.fakeBody(list).toString();
this.parts = RqMtFake.fakeBody(list).toString();
}
@Override
public Iterable<String> head() throws IOException {
return new RqWithHeaders(
this.req,
String.format(
"Content-Type: multipart/form-data; boundary=%s",
RqMultipartFake.BOUNDARY
RqMtFake.BOUNDARY
),
String.format("Content-Length: %s", this.parts.length())
).head();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* @version $Id$
* @since 0.33
*/
public final class RqMultipartSmart implements RqMultipart {
public final class RqMtSmart implements RqMultipart {
/**
* Original request.
*/
Expand All @@ -46,7 +46,7 @@ public final class RqMultipartSmart implements RqMultipart {
* Ctor.
* @param req Original
*/
public RqMultipartSmart(final RqMultipart req) {
public RqMtSmart(final RqMultipart req) {
this.origin = req;
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
import org.takes.rq.RqWithHeaders;

/**
* Test case for {@link RqMultipartBase}.
* Test case for {@link RqMtBase}.
* @author Yegor Bugayenko (yegor@teamed.io)
* @version $Id$
* @since 0.33
* @checkstyle MultipleStringLiteralsCheck (500 lines)
* @checkstyle LineLengthCheck (1 lines)
* @link <a href="http://www.w3.org/TR/html401/interact/forms.html">Forms in HTML</a>
*/
public final class RqMultipartBaseTest {
public final class RqMtBaseTest {

/**
* Carriage return constant.
Expand All @@ -57,38 +57,38 @@ public final class RqMultipartBaseTest {
* Content disposition plus form data.
*/
private static final String CONTENT = String.format(
"%s: %s", RqMultipartBaseTest.DISPOSITION, "form-data; name=\"%s\""
"%s: %s", RqMtBaseTest.DISPOSITION, "form-data; name=\"%s\""
);

/**
* RqMultipartBase can satisfy equals contract.
* RqMtBase can satisfy equals contract.
* @throws IOException if some problem inside
*/
@Test
public void satisfiesEqualsContract() throws IOException {
final String body = "449 N Wolfe Rd, Sunnyvale, CA 94085";
final String part = "t-1";
final Request req = new RqMultipartFake(
final Request req = new RqMtFake(
new RqFake(),
new RqWithHeaders(
new RqFake("", "", body),
RqMultipartBaseTest.contentLengthHeader(
RqMtBaseTest.contentLengthHeader(
(long) body.getBytes().length
),
RqMultipartBaseTest.contentDispositionHeader(
RqMtBaseTest.contentDispositionHeader(
String.format("form-data; name=\"%s\"", part)
)
),
new RqWithHeaders(
new RqFake("", "", ""),
RqMultipartBaseTest.contentLengthHeader(0L),
RqMultipartBaseTest.contentDispositionHeader(
RqMtBaseTest.contentLengthHeader(0L),
RqMtBaseTest.contentDispositionHeader(
"form-data; name=\"data\"; filename=\"a.bin\""
)
)
);
final RqMultipartBase first = new RqMultipartBase(req);
final RqMultipartBase second = new RqMultipartBase(req);
final RqMtBase first = new RqMtBase(req);
final RqMtBase second = new RqMtBase(req);
try {
MatcherAssert.assertThat(first, Matchers.equalTo(second));
} finally {
Expand All @@ -99,20 +99,20 @@ public void satisfiesEqualsContract() throws IOException {
}

/**
* RqMultipartBase can throw exception on no closing boundary found.
* RqMtBase can throw exception on no closing boundary found.
* @throws IOException if some problem inside
*/
@Test(expected = IOException.class)
public void throwsExceptionOnNoClosingBoundaryFound() throws IOException {
new RqMultipartBase(
new RqMtBase(
new RqFake(
Arrays.asList(
"POST /h?a=4 HTTP/1.1",
"Host: rtw.example.com",
"Content-Type: multipart/form-data; boundary=AaB01x",
"Content-Length: 100007"
),
Joiner.on(RqMultipartBaseTest.CRLF).join(
Joiner.on(RqMtBaseTest.CRLF).join(
"--AaB01x",
"Content-Disposition: form-data; fake=\"t2\"",
"",
Expand All @@ -124,23 +124,23 @@ public void throwsExceptionOnNoClosingBoundaryFound() throws IOException {
}

/**
* RqMultipartBase can produce parts with Content-Length.
* RqMtBase can produce parts with Content-Length.
* @throws IOException If some problem inside
*/
@Test
public void producesPartsWithContentLength() throws IOException {
final String part = "t2";
final RqMultipartBase multipart = new RqMultipartBase(
final RqMtBase multipart = new RqMtBase(
new RqFake(
Arrays.asList(
"POST /h?a=4 HTTP/1.1",
"Host: rtw.example.com",
"Content-Type: multipart/form-data; boundary=AaB01x",
"Content-Length: 100007"
),
Joiner.on(RqMultipartBaseTest.CRLF).join(
Joiner.on(RqMtBaseTest.CRLF).join(
"--AaB01x",
String.format(RqMultipartBaseTest.CONTENT, part),
String.format(RqMtBaseTest.CONTENT, part),
"",
"447 N Wolfe Rd, Sunnyvale, CA 94085",
"--AaB01x"
Expand Down
Loading

0 comments on commit 427ec70

Please sign in to comment.