Move to Java 8

pull/30/head
Richard Körber 2017-02-11 11:55:51 +01:00
parent e0e99850f2
commit 0ed0a9219f
7 changed files with 33 additions and 44 deletions

View File

@ -12,7 +12,7 @@ It is an independent open source implementation that is not affiliated with or e
* Supports ACME protocol up to [draft 02](https://tools.ietf.org/html/draft-ietf-acme-acme-02), with a few parts of [draft 03](https://tools.ietf.org/html/draft-ietf-acme-acme-03) and [draft 04](https://tools.ietf.org/html/draft-ietf-acme-acme-04)
* Easy to use Java API
* Requires JRE 7 or higher
* Requires JRE 8 or higher
* Built with maven, packages available at [Maven Central](http://search.maven.org/#search|ga|1|g%3A%22org.shredzone.acme4j%22)
* Small, only requires [jose4j](https://bitbucket.org/b_c/jose4j/wiki/Home) and [slf4j](http://www.slf4j.org/) as dependencies
* Extensive unit tests

View File

@ -13,6 +13,8 @@
*/
package org.shredzone.acme4j;
import java.util.Arrays;
/**
* Enumeration of revocation reasons.
*
@ -53,12 +55,10 @@ public enum RevocationReason {
* @return Matching {@link RevocationReason}, or {@code null} if not known
*/
public static RevocationReason code(int reasonCode) {
for (RevocationReason rr : values()) {
if (rr.reasonCode == reasonCode) {
return rr;
}
}
return null;
return Arrays.stream(values())
.filter(rr -> rr.reasonCode == reasonCode)
.findFirst()
.orElse(null);
}
}

View File

@ -13,6 +13,8 @@
*/
package org.shredzone.acme4j;
import java.util.Arrays;
/**
* Status codes of challenges and authorizations.
*/
@ -30,12 +32,10 @@ public enum Status {
*/
public static Status parse(String str) {
String check = str.toUpperCase();
for (Status s : values()) {
if (s.name().equals(check)) {
return s;
}
}
return Status.UNKNOWN;
return Arrays.stream(values())
.filter(s -> s.name().equals(check))
.findFirst()
.orElse(Status.UNKNOWN);
}
/**

View File

@ -28,11 +28,12 @@ import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.OptionalInt;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -179,10 +180,9 @@ public class DefaultConnection implements Connection {
try {
int rc = conn.getResponseCode();
for (int s : httpStatus) {
if (s == rc) {
return rc;
}
OptionalInt match = Arrays.stream(httpStatus).filter(s -> s == rc).findFirst();
if (match.isPresent()) {
return match.getAsInt();
}
if (!"application/problem+json".equals(conn.getHeaderField(CONTENT_TYPE_HEADER))) {
@ -420,11 +420,11 @@ public class DefaultConnection implements Connection {
return;
}
for (Map.Entry<String, List<String>> entry : conn.getHeaderFields().entrySet()) {
for (String value : entry.getValue()) {
LOG.debug("HEADER {}: {}", entry.getKey(), value);
}
}
conn.getHeaderFields().forEach((key, headers) ->
headers.forEach(value ->
LOG.debug("HEADER {}: {}", key, value)
)
);
}
/**

View File

@ -13,6 +13,7 @@
*/
package org.shredzone.acme4j.util;
import static java.util.stream.Collectors.joining;
import static org.shredzone.acme4j.util.AcmeUtils.parseTimestamp;
import java.io.BufferedReader;
@ -82,18 +83,10 @@ public final class JSON implements Serializable {
* @return {@link JSON} of the read content.
*/
public static JSON parse(InputStream in) throws IOException {
StringBuilder sb = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"))) {
String line = reader.readLine();
while (line != null) {
sb.append(line.trim());
line = reader.readLine();
}
String json = reader.lines().map(String::trim).collect(joining());
return parse(json);
}
return parse(sb.toString());
}
/**

View File

@ -13,6 +13,7 @@
*/
package org.shredzone.acme4j.util;
import static java.util.stream.Collectors.joining;
import static org.shredzone.acme4j.util.AcmeUtils.toAce;
import java.io.IOException;
@ -23,6 +24,7 @@ import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.interfaces.ECKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
@ -86,9 +88,7 @@ public class CSRBuilder {
* Collection of domain names to add
*/
public void addDomains(Collection<String> domains) {
for (String domain : domains) {
addDomain(domain);
}
domains.forEach(this::addDomain);
}
/**
@ -100,9 +100,7 @@ public class CSRBuilder {
* Domain names to add
*/
public void addDomains(String... domains) {
for (String domain : domains) {
addDomain(domain);
}
Arrays.stream(domains).forEach(this::addDomain);
}
/**
@ -237,9 +235,7 @@ public class CSRBuilder {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(namebuilder.build());
for (String domain : namelist) {
sb.append(",DNS=").append(domain);
}
sb.append(namelist.stream().collect(joining(",DNS=", ",DNS=", "")));
return sb.toString();
}

View File

@ -70,8 +70,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>