Skip to content

Commit c5f23dc

Browse files
committed
Replaces multiple System.lineSeparator() calls with a constant for less visual clutter and to avoid calling the same method repeatedly.
1 parent a3ef93f commit c5f23dc

13 files changed

Lines changed: 75 additions & 38 deletions

File tree

TEST

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
1. Move the cursor to this line.
2+
3+
2. Press v and move the cursor to the fifth item below. Notice that the
4+
text is highlighted.
5+
6+
3. Press the : character. At the bottom of the screen :'<,'> will appear.
7+
8+
4. Type w TEST , where TEST is a filename that does not exist yet. Verify
9+
that you see :'<,'>w TEST before you press <ENTER>.
10+
11+
5. Vim will write the selected lines to the file TEST. Use :!dir or :!ls
12+
to see it. Do not remove it yet! We will use it in the next lesson.
13+
14+
NOTE: Pressing v starts Visual selection. You can move the cursor around

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@
6161
<artifactId>cobertura-maven-plugin</artifactId>
6262
<version>2.7</version>
6363
<configuration>
64-
<formats>
65-
<format>html</format>
66-
<format>xml</format>
67-
</formats>
68-
</configuration>
64+
<formats>
65+
<format>html</format>
66+
<format>xml</format>
67+
</formats>
68+
</configuration>
6969
<reportSets>
7070
<reportSet>
7171
<reports>

src/main/java/com/github/mh120888/basichttpmessage/BasicHTTPResponse.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.util.HashMap;
77
import java.util.Map;
88

9+
import static com.github.mh120888.httpmessage.MessageFormatting.CRLF;
10+
911
public class BasicHTTPResponse implements HTTPResponse {
1012
int status;
1113
String version = "";
@@ -41,16 +43,16 @@ public String getFormattedResponse() {
4143

4244
public String getStatusLineAndHeaders() {
4345
String result = "";
44-
result += version + " " + status + " " + getStatusText() + System.lineSeparator();
45-
result += getFormattedHeaders() + System.lineSeparator();
46+
result += version + " " + status + " " + getStatusText() + CRLF;
47+
result += getFormattedHeaders() + CRLF;
4648

4749
return result;
4850
}
4951

5052
String getFormattedHeaders() {
5153
String result = "";
5254
for (Map.Entry<String, String> header : headers.entrySet()) {
53-
result += header.getKey() + ": " + header.getValue() + System.lineSeparator();
55+
result += header.getKey() + ": " + header.getValue() + CRLF;
5456
}
5557
return result;
5658
}

src/main/java/com/github/mh120888/basichttpmessage/RequestParser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.util.HashMap;
55
import java.util.Map;
66

7+
import static com.github.mh120888.httpmessage.MessageFormatting.CRLF;
8+
79
public class RequestParser {
810
private String request;
911

@@ -45,7 +47,7 @@ public HashMap getParams(String pathWithParams) {
4547

4648
public HashMap getHeaders(String headerInput) {
4749
HashMap<String, String> headers = new HashMap<>();
48-
String[] splitUpHeaders = headerInput.split(System.lineSeparator());
50+
String[] splitUpHeaders = headerInput.split(CRLF);
4951
for (String headerPair : splitUpHeaders) {
5052
String[] separatePair = headerPair.split(":");
5153
String headerName = separatePair[0];

src/main/java/com/github/mh120888/cobspecapp/GetStaticResourceAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private byte[] getBodyForDirectory() {
6969
}
7070

7171
private String renderHTMLLinkForFile(String fileName) {
72-
return "<a href=\"/" + fileName + "\">" + fileName + "</a>\n";
72+
return "<a href=\"/" + fileName + "\">" + fileName + "</a>\n";
7373
}
7474

7575
private byte[] getBodyForFile() {
@@ -87,3 +87,4 @@ private boolean isPathADirectory() {
8787
return fileIO.isDirectory(filePath);
8888
}
8989
}
90+

src/main/java/com/github/mh120888/cobspecapp/LogsAction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.github.mh120888.httpmessage.HTTPResponse;
77
import com.github.mh120888.httpmessage.HTTPStatus;
88

9+
import static com.github.mh120888.httpmessage.MessageFormatting.CRLF;
10+
911
public class LogsAction implements Application {
1012
private String correctCredentials = "admin:hunter2";
1113

@@ -25,7 +27,7 @@ private void setUnauthorizedResponse(HTTPResponse response) {
2527

2628
private void setAuthorizedResponse(HTTPResponse response) {
2729
response.setStatus(HTTPStatus.OK);
28-
response.setBody(String.join(System.lineSeparator(), Logger.getLog()).getBytes());
30+
response.setBody(String.join(CRLF, Logger.getLog()).getBytes());
2931
}
3032

3133
private boolean isAuthorized(HTTPRequest request) {

src/main/java/com/github/mh120888/cobspecapp/ParametersAction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import java.util.Map;
99

10+
import static com.github.mh120888.httpmessage.MessageFormatting.CRLF;
11+
1012
public class ParametersAction implements Application {
1113
private HTTPRequest request;
1214

@@ -40,7 +42,7 @@ private byte[] getBody() {
4042
private String formatParametersForBody(Map<String, String> parameters) {
4143
String body = "";
4244
for (Map.Entry<String, String> entry : parameters.entrySet()) {
43-
body += entry.getKey() + " = " + entry.getValue() + System.lineSeparator();
45+
body += entry.getKey() + " = " + entry.getValue() + CRLF;
4446
}
4547
return body;
4648
}

src/main/java/com/github/mh120888/cobspecapp/Router.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,3 @@ private static void configureRoutesBasedOnPublicDirectory() {
9696
addRoute("HEAD", "/index", headStaticResourceAction);
9797
}
9898
}
99-
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.github.mh120888.httpmessage;
2+
3+
public class MessageFormatting {
4+
public static final String CRLF = System.lineSeparator();
5+
6+
}

src/main/java/com/github/mh120888/server/CommandLineArgsParser.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import java.util.HashMap;
44

5+
import static com.github.mh120888.httpmessage.MessageFormatting.CRLF;
6+
57
public class CommandLineArgsParser {
6-
private final static String usage = "Usage: java -jar javaserver-1.0-SNAPSHOT.jar [-pd]" + System.lineSeparator() +
7-
"\t-p <port number> {80}" + System.lineSeparator() +
8+
private final static String usage = "Usage: java -jar javaserver-1.0-SNAPSHOT.jar [-pd]" + CRLF +
9+
"\t-p <port number> {80}" + CRLF +
810
"\t-d <public directory> {.} (required)";
911

1012
public static HashMap<String, String> groupOptions(String[] args) {

0 commit comments

Comments
 (0)