Skip to content

Commit

Permalink
Fixed badly renamed comments, continue to refactor Utf8String usage (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
igor committed Dec 19, 2018
1 parent ec5a55e commit 33a5f52
Show file tree
Hide file tree
Showing 30 changed files with 67 additions and 60 deletions.
15 changes: 8 additions & 7 deletions src/main/java/org/takes/facets/auth/PsBasic.java
Expand Up @@ -35,6 +35,7 @@
import java.util.regex.Pattern;
import javax.xml.bind.DatatypeConverter;
import lombok.EqualsAndHashCode;
import org.cactoos.text.TrimmedText;
import org.takes.Request;
import org.takes.Response;
import org.takes.facets.flash.RsFlash;
Expand Down Expand Up @@ -98,11 +99,11 @@ public Opt<Identity> enter(final Request request) throws IOException {
new RqHref.Base(request).href()
);
}
final String decoded = new Utf8String(
final String decoded = new TrimmedText(new Utf8String(
DatatypeConverter.parseBase64Binary(
PsBasic.AUTH.split(headers.next())[1]
)
).asString().trim();
)).asString();
final String user = decoded.split(":")[0];
final Opt<Identity> identity = this.entry.enter(
user,
Expand Down Expand Up @@ -309,7 +310,7 @@ private Opt<String> urn(final String user, final String pwd) {
/**
* Creates a key for
* {@link org.takes.facets.auth.PsBasic.Default#usernames} map.
* @param unified User asString made of 3 urlencoded substrings
* @param unified User string made of 3 urlencoded substrings
* separated with non-urlencoded space characters.
* @return Login and password parts with <pre>%20</pre> replaced with
* <pre>+</pre>.
Expand All @@ -326,7 +327,7 @@ private static String key(final String unified) {
}

/**
* Checks if a unified user asString is correctly formatted.
* Checks if a unified user string is correctly formatted.
* @param unified String with urlencoded user login, password and urn
* separated with spaces.
*/
Expand All @@ -345,9 +346,9 @@ private static void validateUser(final String unified) {
}

/**
* Counts spaces in a asString.
* @param txt Any asString.
* @return Amount of spaces in asString.
* Counts spaces in a string.
* @param txt Any string.
* @return Amount of spaces in string.
*/
private static int countSpaces(final String txt) {
int spaces = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/takes/facets/auth/codecs/CcAes.java
Expand Up @@ -132,7 +132,7 @@ public Identity decode(final byte[] bytes) throws IOException {
}

/**
* Encrypt the given asBytes using AES.
* Encrypt the given bytes using AES.
*
* @param bytes Bytes to encrypt
* @return Encrypted byte using AES algorithm
Expand Down Expand Up @@ -171,7 +171,7 @@ private static byte[] withCorrectBlockSize(final byte[] key) {
if (key.length != CcAes.BLOCK) {
throw new IllegalArgumentException(
String.format(
"the length of the AES key must be exactly %d asBytes",
"the length of the AES key must be exactly %d bytes",
CcAes.BLOCK
)
);
Expand All @@ -180,10 +180,10 @@ private static byte[] withCorrectBlockSize(final byte[] key) {
}

/**
* Decrypt the given asBytes using AES.
* Decrypt the given bytes using AES.
*
* @param bytes Bytes to decrypt
* @return Decrypted asBytes
* @return Decrypted bytes
* @throws IOException for all unexpected exceptions
*/
private byte[] decrypt(final byte[] bytes) throws IOException {
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/org/takes/facets/auth/codecs/CcPlain.java
Expand Up @@ -29,8 +29,12 @@
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.EqualsAndHashCode;
import org.cactoos.Text;
import org.cactoos.list.ListOf;
import org.cactoos.text.SplitText;
import org.takes.facets.auth.Identity;
import org.takes.misc.Utf8String;

Expand Down Expand Up @@ -62,17 +66,17 @@ public byte[] encode(final Identity identity) throws IOException {

@Override
public Identity decode(final byte[] bytes) throws IOException {
final String[] parts = new Utf8String(bytes).asString().split(";");
final Map<String, String> map = new HashMap<>(parts.length);
for (int idx = 1; idx < parts.length; ++idx) {
final String[] pair = parts[idx].split("=");
final List<Text> parts = new ListOf<>(new SplitText(new Utf8String(bytes), ";"));
final Map<String, String> map = new HashMap<>(parts.size());
for (int idx = 1; idx < parts.size(); ++idx) {
final String[] pair = parts.get(idx).asString().split("=");
try {
map.put(pair[0], CcPlain.decode(pair[1]));
} catch (final IllegalArgumentException ex) {
throw new DecodingException(ex);
}
}
return new Identity.Simple(CcPlain.decode(parts[0]), map);
return new Identity.Simple(CcPlain.decode(parts.get(0).asString()), map);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/takes/facets/auth/codecs/CcSalted.java
Expand Up @@ -69,9 +69,9 @@ public Identity decode(final byte[] bytes) throws IOException {
}

/**
* Salt the asString.
* Salt the string.
* @param text Original text to salt
* @return Salted asString
* @return Salted string
*/
@SuppressWarnings("PMD.AvoidArrayLoops")
private static byte[] salt(final byte[] text) {
Expand All @@ -89,7 +89,7 @@ private static byte[] salt(final byte[] text) {
}

/**
* Un-salt the asString.
* Un-salt the string.
* @param text Salted text
* @return Original text
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/facets/auth/codecs/CcXor.java
Expand Up @@ -79,7 +79,7 @@ public Identity decode(final byte[] bytes) throws IOException {
}

/**
* XOR array of asBytes.
* XOR array of bytes.
* @param input The input to XOR
* @return Encrypted output
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/facets/auth/codecs/Codec.java
Expand Up @@ -36,7 +36,7 @@
public interface Codec {

/**
* Encode identity into asBytes.
* Encode identity into bytes.
* @param identity The identity
* @return Text
* @throws IOException If fails
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/takes/facets/auth/signatures/SiHmac.java
Expand Up @@ -134,11 +134,11 @@ private static int bitLength(final int bits) {
}

/**
* Encrypt the given asBytes using HMAC.
* Encrypt the given bytes using HMAC.
*
* @param bytes
* Bytes to encrypt
* @return Encrypted asBytes
* @return Encrypted bytes
* @throws IOException
* for all unexpected exceptions
*/
Expand Down
Expand Up @@ -35,7 +35,7 @@
public interface Signature {

/**
* Create signature for data asBytes.
* Create signature for data bytes.
* @param data The data to be signed
* @return Signature
* @throws IOException If anything fails
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/facets/cookies/RsWithCookie.java
Expand Up @@ -115,7 +115,7 @@ public RsWithCookie(final Response res, final CharSequence name,
}

/**
* Build cookie asString.
* Build cookie string.
* @param name Cookie name
* @param value Value of it
* @param attrs Optional attributes, for example "Path=/"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/facets/flash/RsFlash.java
Expand Up @@ -106,7 +106,7 @@ public final class RsFlash extends RsWrap {
private static final String TEXT_FORMAT = "%s/%s";

/**
* To asString.
* To string.
*/
private final CharSequence text;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/takes/facets/fork/FkEncoding.java
Expand Up @@ -48,7 +48,7 @@
* new FkEncoding("", response)
* )</pre>
*
* <p>Empty asString as an encoding means that the fork should match
* <p>Empty string as an encoding means that the fork should match
* in any case.
*
* <p>The class is immutable and thread-safe.
Expand All @@ -64,7 +64,7 @@ public final class FkEncoding implements Fork {
private static final Pattern ENCODING_SEP = Pattern.compile("\\s*,\\s*");

/**
* Encoding we can deliver (or empty asString).
* Encoding we can deliver (or empty string).
*/
private final String encoding;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/facets/fork/RqRegex.java
Expand Up @@ -41,7 +41,7 @@
public interface RqRegex extends Request {

/**
* Get matcher of query asString.
* Get matcher of query string.
* @return Matcher
*/
Matcher matcher();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/facets/hamcrest/HmBody.java
Expand Up @@ -147,7 +147,7 @@ private static InputStream itemBody(final Body item) throws IOException {
}

/**
* InputStream as asBytes.
* InputStream as bytes.
* @param input Input
* @return Bytes
* @throws IOException If some problem inside
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/facets/hamcrest/HmHeader.java
Expand Up @@ -46,7 +46,7 @@
public final class HmHeader<T extends Head> extends TypeSafeMatcher<T> {

/**
* Values asString used in description of mismatches.
* Values string used in description of mismatches.
*/
private static final String VALUES_STR = " -> values: ";

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/takes/http/MainRemote.java
Expand Up @@ -33,6 +33,7 @@
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import lombok.EqualsAndHashCode;
import org.cactoos.text.TrimmedText;
import org.takes.misc.Utf8String;

/**
Expand Down Expand Up @@ -155,7 +156,7 @@ private static int port(final File file) throws Exception {
break;
}
}
port = Integer.parseInt(new Utf8String(buf).asString().trim());
port = Integer.parseInt(new TrimmedText(new Utf8String(buf)).asString());
}
return port;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/takes/misc/EnglishLowerCase.java
Expand Up @@ -26,7 +26,7 @@
import java.util.Locale;

/**
* English lower case asString representation.
* English lower case string representation.
* @since 0.33
*/
public final class EnglishLowerCase {
Expand All @@ -53,7 +53,7 @@ public EnglishLowerCase(final String string) {
}

/**
* Returns asString value.
* Returns string value.
* @return String value
*/
public String string() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/misc/Utf8String.java
Expand Up @@ -53,7 +53,7 @@ public Utf8String(final String string) {

/**
* Ctor.
* @param bytes Bytes to construct UTF-8 asString value
* @param bytes Bytes to construct UTF-8 string value
*/
public Utf8String(final byte... bytes) {
this(new String(bytes, Charset.forName(Utf8String.ENCODING)));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/rq/CapInputStream.java
Expand Up @@ -41,7 +41,7 @@ final class CapInputStream extends InputStream {
private final InputStream origin;

/**
* More asBytes to read.
* More bytes to read.
*/
private long more;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/rq/ChunkedInputStream.java
Expand Up @@ -199,7 +199,7 @@ private enum State {
*/
R,
/**
* Inside quoted asString.
* Inside quoted string.
*/
QUOTED_STRING,
/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/rq/RqLengthAware.java
Expand Up @@ -39,7 +39,7 @@
* most cases, the browser will not close the request and will always
* return positive number in available() method. Thus, you won't be
* able to reach the end of the stream ever. The browser wants you
* to respect the "Content-Length" header and read as many asBytes
* to respect the "Content-Length" header and read as many bytes
* as it requests. To solve that, just wrap your request into this
* decorator.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/rq/RqLive.java
Expand Up @@ -176,7 +176,7 @@ private static Integer legalCharacter(final Opt<Integer> data,
* @param input Stream
* @param data Empty or current data
* @param available Indicates whether or not it should check first if there
* are available asBytes
* are available bytes
* @return Next or current data
* @throws IOException if input.read() fails
*/
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/takes/rs/RsPrint.java
Expand Up @@ -79,7 +79,7 @@ public RsPrint(final Response res) {
}

/**
* Print it into asString.
* Print it into string.
* @return Entire HTTP response
* @throws IOException If fails
*/
Expand All @@ -95,7 +95,7 @@ public String asString() throws IOException {
}

/**
* Print body into asString.
* Print body into string.
* @return Entire body of HTTP response
* @throws IOException If fails
*/
Expand All @@ -106,7 +106,7 @@ public String printBody() throws IOException {
}

/**
* Print head into asString.
* Print head into string.
* @return Entire head of HTTP response
* @throws IOException If fails
* @since 0.10
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/takes/facets/auth/PsBasicTest.java
Expand Up @@ -288,11 +288,11 @@ private static String urn(final String user) {
}

/**
* Generate the asString used on the request that store information about
* Generate the string used on the request that store information about
* authentication.
* @param user Username
* @param pass Password
* @return Header asString.
* @return Header string.
*/
private static String header(final String user, final String pass) {
final String auth = String.format("%s:%s", user, pass);
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/takes/facets/auth/social/PsGithubTest.java
Expand Up @@ -61,23 +61,23 @@ public final class PsGithubTest {
private static final String GIT_HUB_TOKEN = "GitHubToken";

/**
* XPath access_token asString.
* XPath access_token string.
*/
private static final String ACCESS_TOKEN = "access_token";

/**
* XPath login asString.
* XPath login string.
*/
private static final String LOGIN = "login";

/**
* Octocat URL asString.
* Octocat URL string.
*/
private static final String OCTOCAT_GIF_URL =
"https://github.com/img/octocat.gif";

/**
* XPath octocat asString.
* XPath octocat string.
*/
private static final String OCTOCAT = "octocat";

Expand Down

0 comments on commit 33a5f52

Please sign in to comment.