Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.

Commit c6fa1b0

Browse files
committed
Bug fixes & toString unfinal
1 parent 103c135 commit c6fa1b0

8 files changed

Lines changed: 39 additions & 56 deletions

File tree

src/main/java/com/kttdevelopment/simplehttpserver/HttpSessionHandler.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.sun.net.httpserver.HttpExchange;
55

66
import java.util.*;
7-
import java.util.function.Predicate;
87

98
/**
109
* This class assigns {@link HttpSession} to every client.
@@ -132,12 +131,12 @@ public synchronized final void updateLastAccessTime(){
132131

133132
@SuppressWarnings("StringBufferReplaceableByString")
134133
@Override
135-
public final String toString(){
134+
public String toString(){
136135
final StringBuilder OUT = new StringBuilder();
137-
OUT.append("HttpSession").append('{');
138-
OUT.append("sessionID").append('=').append(sessionID).append(", ");
139-
OUT.append("creationTime").append('=').append(creationTime).append(", ");
140-
OUT.append("lastAccessTime").append('=').append(lastAccessTime);
136+
OUT.append("HttpSession") .append('{');
137+
OUT.append("sessionID") .append('=') .append(sessionID) .append(", ");
138+
OUT.append("creationTime") .append('=') .append(creationTime) .append(", ");
139+
OUT.append("lastAccessTime") .append('=') .append(lastAccessTime);
141140
OUT.append('}');
142141
return OUT.toString();
143142
}

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpCookie.java

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ public class SimpleHttpCookie {
3030
/**
3131
* Creates an HTTP cookie. All fields except for <code>name</code>, <code>secure</code>, <code>httpOnly</code>, and <code>value</code> can be set to null if unused.
3232
*
33-
* @deprecated Use {@link Builder} class instead. This method will be removed in the future
34-
*
3533
* @param name name of the cookie
3634
* @param value value of the cookie
3735
* @param domain what domain to send the cookie to
@@ -45,8 +43,7 @@ public class SimpleHttpCookie {
4543
* @since 02.00.00
4644
* @author Ktt Development
4745
*/
48-
@Deprecated
49-
public SimpleHttpCookie(final String name, final String value, final String domain, final String path, final String sameSite, final Date expires, final Integer maxAge, final Boolean secure, final Boolean httpOnly){
46+
private SimpleHttpCookie(final String name, final String value, final String domain, final String path, final String sameSite, final Date expires, final Integer maxAge, final Boolean secure, final Boolean httpOnly){
5047
if(name == null)
5148
throw new NullPointerException("Cookie name can not be null");
5249
else
@@ -64,41 +61,7 @@ public SimpleHttpCookie(final String name, final String value, final String doma
6461
this.httpOnly = httpOnly;
6562
}
6663

67-
/**
68-
* Converts the cookie to a readable string for the cookie header.
69-
*
70-
* @deprecated Use {@link #toCookieHeaderString()} instead
71-
*
72-
* @return cookie header
73-
*
74-
* @see SimpleHttpExchange#setCookie(SimpleHttpCookie)
75-
* @since 02.00.00
76-
* @author Ktt Development
77-
*/
78-
@SuppressWarnings({"ConstantConditions", "SpellCheckingInspection"})
79-
@Override @Deprecated
80-
public final String toString(){
81-
final StringBuilder OUT = new StringBuilder();
82-
83-
OUT.append(name).append("=").append(value);
84-
if(expires != null)
85-
OUT.append("; Expires=").append(new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(expires)).append(" GMT");
86-
if(maxAge != null)
87-
OUT.append("; Max-Age=").append(maxAge);
88-
if(domain != null)
89-
OUT.append("; Domain=").append(domain);
90-
if(path != null)
91-
OUT.append("; Path=").append(path);
92-
if(secure != null && secure)
93-
OUT.append("; Secure=").append(secure);
94-
if(httpOnly != null && httpOnly)
95-
OUT.append("; HttpOnly=").append(httpOnly);
96-
if(sameSite != null)
97-
OUT.append("; SameSite=").append(sameSite);
98-
99-
return OUT.toString();
100-
}
101-
64+
@SuppressWarnings("SpellCheckingInspection")
10265
private final SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");
10366

10467
/**
@@ -130,6 +93,25 @@ public final String toCookieHeaderString(){
13093
return OUT.toString();
13194
}
13295

96+
@SuppressWarnings("StringBufferReplaceableByString")
97+
public String toString(){
98+
final StringBuilder OUT = new StringBuilder();
99+
100+
OUT.append("SimpleHttpCookie") .append('{');
101+
OUT.append("name") .append('=') .append(name) .append(", ");
102+
OUT.append("value") .append('=') .append(value) .append(", ");
103+
OUT.append("expires") .append('=') .append(expires) .append(", ");
104+
OUT.append("maxAge") .append('=') .append(maxAge) .append(", ");
105+
OUT.append("domain") .append('=') .append(domain) .append(", ");
106+
OUT.append("path") .append('=') .append(path) .append(", ");
107+
OUT.append("secure") .append('=') .append(secure) .append(", ");
108+
OUT.append("httpOnly") .append('=') .append(httpOnly) .append(", ");
109+
OUT.append("sameSite") .append('=') .append(sameSite);
110+
OUT.append('}');
111+
112+
return OUT.toString();
113+
}
114+
133115
/**
134116
* Builder class for {@link SimpleHttpCookie}.
135117
*

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpExchangeImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public synchronized final void setAttribute(final String name, final Object valu
417417

418418
@SuppressWarnings("StringBufferReplaceableByString")
419419
@Override
420-
public final String toString(){
420+
public String toString(){
421421
final StringBuilder OUT = new StringBuilder();
422422
OUT.append("SimpleHttpExchange").append('{');
423423
OUT.append("httpServer") .append('=') .append(httpServer) .append(", ");

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpServer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public abstract class SimpleHttpServer {
2626
/**
2727
* Create an empty {@link SimpleHttpServer}. Applications don't use this method.
2828
*
29-
* @see SimpleHttpServerImpl#create(Integer, Integer)
29+
* @see SimpleHttpServerImpl#createHttpServer(Integer, Integer)
3030
* @since 02.00.00
3131
* @author Ktt Development
3232
*/
@@ -44,7 +44,7 @@ public abstract class SimpleHttpServer {
4444
* @author Ktt Development
4545
*/
4646
public static SimpleHttpServer create() throws IOException {
47-
return SimpleHttpServerImpl.create(null,null);
47+
return SimpleHttpServerImpl.createHttpServer(null, null);
4848
}
4949

5050
/**
@@ -61,7 +61,7 @@ public static SimpleHttpServer create() throws IOException {
6161
* @author Ktt Development
6262
*/
6363
public static SimpleHttpServer create(final int port) throws IOException {
64-
return SimpleHttpServerImpl.create(port,null);
64+
return SimpleHttpServerImpl.createHttpServer(port, null);
6565
}
6666

6767
/**
@@ -79,7 +79,7 @@ public static SimpleHttpServer create(final int port) throws IOException {
7979
* @author Ktt Development
8080
*/
8181
public static SimpleHttpServer create(final int port, final int backlog) throws IOException {
82-
return SimpleHttpServerImpl.create(port,backlog);
82+
return SimpleHttpServerImpl.createHttpServer(port,backlog);
8383
}
8484

8585
//

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpServerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ final class SimpleHttpServerImpl extends SimpleHttpServer {
4040
* @since 03.04.00
4141
* @author Ktt Development
4242
*/
43-
static SimpleHttpServer create(final Integer port, final Integer backlog) throws IOException{
43+
static SimpleHttpServer createHttpServer(final Integer port, final Integer backlog) throws IOException{
4444
return new SimpleHttpServerImpl(port,backlog);
4545
}
4646

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpsServer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public abstract class SimpleHttpsServer extends SimpleHttpServer {
2222
/**
2323
* Create an empty {@link SimpleHttpsServer}. Applications don't use this method.
2424
*
25-
* @see SimpleHttpsServerImpl#create(Integer, Integer)
25+
* @see SimpleHttpsServerImpl#createSimpleHttpsServer(Integer, Integer)
2626
* @since 02.00.00
2727
* @author Ktt Development
2828
*/
@@ -40,7 +40,7 @@ public abstract class SimpleHttpsServer extends SimpleHttpServer {
4040
* @author Ktt Development
4141
*/
4242
public static SimpleHttpsServer create() throws IOException {
43-
return SimpleHttpsServerImpl.create(null,null);
43+
return SimpleHttpsServerImpl.createSimpleHttpsServer(null, null);
4444
}
4545

4646
/**
@@ -57,7 +57,7 @@ public static SimpleHttpsServer create() throws IOException {
5757
* @author Ktt Development
5858
*/
5959
public static SimpleHttpsServer create(final int port) throws IOException {
60-
return SimpleHttpsServerImpl.create(port,null);
60+
return SimpleHttpsServerImpl.createSimpleHttpsServer(port, null);
6161
}
6262

6363
/**
@@ -75,7 +75,7 @@ public static SimpleHttpsServer create(final int port) throws IOException {
7575
* @author Ktt Development
7676
*/
7777
public static SimpleHttpsServer create(final int port, final int backlog) throws IOException {
78-
return SimpleHttpsServerImpl.create(port,backlog);
78+
return SimpleHttpsServerImpl.createSimpleHttpsServer(port,backlog);
7979
}
8080

8181
//

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpsServerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final public class SimpleHttpsServerImpl extends SimpleHttpsServer {
3939
* @since 03.04.00
4040
* @author Ktt Development
4141
*/
42-
static SimpleHttpsServer create(final Integer port, final Integer backlog) throws IOException{
42+
static SimpleHttpsServer createSimpleHttpsServer(final Integer port, final Integer backlog) throws IOException{
4343
return new SimpleHttpsServerImpl(port,backlog);
4444
}
4545

@@ -74,6 +74,7 @@ public final HttpsConfigurator getHttpsConfigurator(){
7474

7575
// region copySimpleHttpServerImpl
7676

77+
@SuppressWarnings("SpellCheckingInspection")
7778
@Override
7879
public synchronized final InetSocketAddress bind(final int port) throws IOException{
7980
final InetSocketAddress addr = new InetSocketAddress(port);

src/main/java/com/kttdevelopment/simplehttpserver/handler/ThrottledHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public final void handle(final HttpExchange exchange) throws IOException{
4646
}
4747
}
4848

49+
@SuppressWarnings("StringBufferReplaceableByString")
4950
@Override
5051
public String toString(){
5152
final StringBuilder OUT = new StringBuilder();

0 commit comments

Comments
 (0)