Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#594 RqMultipart.java - Removing the warning suppression (PMD.ConstructorOnlyInitializesOrCallOtherConstructors) #641

Merged
merged 4 commits into from
Mar 6, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions src/main/java/org/takes/rq/RqMultipart.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,26 +128,14 @@ final class Base extends RqWrap implements RqMultipart {
* @param req Original request
* @throws IOException If fails
* @checkstyle ExecutableStatementCountCheck (2 lines)
* @todo #558:30min Base ctor. According to new qulice version,
* constructor must contain only variables initialization and other
* constructor calls. Refactor code according to that rule and
* remove `ConstructorOnlyInitializesOrCallOtherConstructors`
* warning suppression.
*/
@SuppressWarnings
(
"PMD.ConstructorOnlyInitializesOrCallOtherConstructors"
)
public Base(final Request req) throws IOException {
super(req);
final InputStream stream = new RqLengthAware(req).body();
this.body = Channels.newChannel(stream);
this.buffer = ByteBuffer.allocate(
// @checkstyle MagicNumberCheck (1 line)
Math.min(8192, stream.available())
);
this.body = Base.body(req);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dalifreire making a static method is a workaround not a solution. Here you could store the stream as a field and create Channel in requests method and pass the created variable to copy and make.

this.buffer = Base.buffer(req);
this.map = this.requests(req);
}

@Override
public Iterable<Request> part(final CharSequence name) {
final List<Request> values = this.map
Expand Down Expand Up @@ -176,6 +164,32 @@ public Iterable<Request> part(final CharSequence name) {
public Iterable<String> names() {
return this.map.keySet();
}

/**
* Returns the ReadableByteChannel based on request body.
* @param req Original request
* @return The ReadableByteChannel based on request body.
* @throws IOException If fails
*/
private static ReadableByteChannel body(final Request req)
throws IOException {
return Channels.newChannel(new RqLengthAware(req).body());
}

/**
* Returns the ByteBuffer for the request body.
* @param req Original request
* @return The ByteBuffer for the request body.
* @throws IOException If fails
*/
private static ByteBuffer buffer(final Request req)
throws IOException {
return ByteBuffer.allocate(
// @checkstyle MagicNumberCheck (1 line)
Math.min(8192, new RqLengthAware(req).body().available())
);
}

/**
* Build a request for each part of the origin request.
* @param req Origin request
Expand Down