You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/12/19 10:33:04 UTC
[1/2] jena git commit: Reformat
Repository: jena
Updated Branches:
refs/heads/master c10dff436 -> 2cb13230b
Reformat
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/f01a2926
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/f01a2926
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/f01a2926
Branch: refs/heads/master
Commit: f01a292639b2aa3df2020fff8f12d5028845bcbb
Parents: c10dff4
Author: Andy Seaborne <an...@apache.org>
Authored: Sun Dec 18 17:13:09 2016 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Sun Dec 18 17:13:09 2016 +0000
----------------------------------------------------------------------
.../org/apache/jena/atlas/lib/StrUtils.java | 214 ++++++++-----------
1 file changed, 94 insertions(+), 120 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/f01a2926/jena-base/src/main/java/org/apache/jena/atlas/lib/StrUtils.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/org/apache/jena/atlas/lib/StrUtils.java b/jena-base/src/main/java/org/apache/jena/atlas/lib/StrUtils.java
index b0b4721..e599cc4 100644
--- a/jena-base/src/main/java/org/apache/jena/atlas/lib/StrUtils.java
+++ b/jena-base/src/main/java/org/apache/jena/atlas/lib/StrUtils.java
@@ -19,50 +19,44 @@
package org.apache.jena.atlas.lib;
import static java.util.Arrays.stream ;
-import static java.util.stream.Collectors.joining ;
-import static java.util.stream.Collectors.toList ;
-
-import java.io.UnsupportedEncodingException ;
-import java.util.List ;
-import java.util.Map ;
+import static java.util.stream.Collectors.joining;
+import static java.util.stream.Collectors.toList;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+import java.util.Map;
+/** Some functions that act on strings */
public class StrUtils //extends StringUtils
{
private StrUtils() {}
/** strjoin with a newline as the separator */
- public static String strjoinNL(String... args)
- {
- return join("\n", args) ;
+ public static String strjoinNL(String... args) {
+ return join("\n", args);
}
-
+
/** strjoin with a newline as the separator */
- public static String strjoinNL(List<String> args)
- {
- return join("\n", args) ;
+ public static String strjoinNL(List<String> args) {
+ return join("\n", args);
}
-
+
/** Concatentate strings, using a separator */
- public static String strjoin(String sep, String... args)
- {
- return join(sep, args) ;
+ public static String strjoin(String sep, String... args) {
+ return join(sep, args);
}
-
- /** Concatentate string, using a separator */
- public static String strjoin(String sep, List<String> args)
- {
- return join(sep, args) ;
+
+ /** Concatentate strings, using a separator */
+ public static String strjoin(String sep, List<String> args) {
+ return join(sep, args);
}
-
- private static String join(String sep, List<String> a)
- {
+
+ private static String join(String sep, List<String> a) {
return a.stream().collect(joining(sep));
}
-
- private static String join(String sep, String...a)
- {
- return stream(a).collect(joining(sep));
+
+ private static String join(String sep, String... a) {
+ return stream(a).collect(joining(sep));
}
public static final int CMP_GREATER = +1 ;
@@ -72,8 +66,7 @@ public class StrUtils //extends StringUtils
public static final int CMP_UNEQUAL = -9 ;
public static final int CMP_INDETERMINATE = 2 ;
- public static int strCompare(String s1, String s2)
- {
+ public static int strCompare(String s1, String s2) {
// Value is the difference of the first differing chars
int x = s1.compareTo(s2) ;
if ( x < 0 ) return CMP_LESS ;
@@ -82,8 +75,7 @@ public class StrUtils //extends StringUtils
throw new InternalErrorException("String comparison failure") ;
}
- public static int strCompareIgnoreCase(String s1, String s2)
- {
+ public static int strCompareIgnoreCase(String s1, String s2) {
// Value is the difference of the first differing chars
int x = s1.compareToIgnoreCase(s2) ;
if ( x < 0 ) return CMP_LESS ;
@@ -92,51 +84,45 @@ public class StrUtils //extends StringUtils
throw new InternalErrorException("String comparison failure") ;
}
- public static byte[] asUTF8bytes(String s)
- {
+ public static byte[] asUTF8bytes(String s) {
try { return s.getBytes("UTF-8") ; }
catch (UnsupportedEncodingException ex)
{ throw new InternalErrorException("UTF-8 not supported!") ; }
}
- public static String fromUTF8bytes(byte[] bytes)
- {
+ public static String fromUTF8bytes(byte[] bytes) {
try { return new String(bytes, "UTF-8") ; }
catch (UnsupportedEncodingException ex)
{ throw new InternalErrorException("UTF-8 not supported!") ; }
}
- public static String str(Object x)
- {
+ public static String str(Object x) {
if ( x == null ) return "<null>" ;
return x.toString() ;
}
-
+
/** Split but also trim whiespace. */
- public static String[] split(String s, String splitStr)
- {
- return stream(s.split(splitStr)).map(String::trim).toArray(String[]::new);
+ public static String[] split(String s, String splitStr) {
+ return stream(s.split(splitStr)).map(String::trim).toArray(String[]::new) ;
}
- /** Does one string contain another string?
+ /**
+ * Does one string contain another string?
+ *
* @param str1
* @param str2
* @return true if str1 contains str2
*/
- public final static boolean contains(String str1, String str2)
- {
+ public final static boolean contains(String str1, String str2) {
return str1.contains(str2) ;
}
- public final static String replace(String string, String target, String replacement)
- {
+ public final static String replace(String string, String target, String replacement) {
return string.replace(target, replacement) ;
}
-
- public static String substitute(String str, Map<String, String>subs)
- {
- for ( Map.Entry<String, String> e : subs.entrySet() )
- {
+
+ public static String substitute(String str, Map<String, String> subs) {
+ for ( Map.Entry<String, String> e : subs.entrySet() ) {
String param = e.getKey() ;
if ( str.contains(param) )
str = str.replace(param, e.getValue()) ;
@@ -144,54 +130,49 @@ public class StrUtils //extends StringUtils
return str ;
}
- public static String strform(Map<String, String>subs, String... args)
- {
- return substitute(strjoinNL(args),subs) ;
+ public static String strform(Map<String, String> subs, String... args) {
+ return substitute(strjoinNL(args), subs) ;
}
- public static String chop(String x)
- {
+ public static String chop(String x) {
if ( x.length() == 0 )
return x ;
- return x.substring(0, x.length()-1) ;
+ return x.substring(0, x.length() - 1) ;
}
- public static String noNewlineEnding(String x)
- {
- while ( x.endsWith("\n") || x.endsWith("\r") )
+ public static String noNewlineEnding(String x) {
+ while (x.endsWith("\n") || x.endsWith("\r"))
x = StrUtils.chop(x) ;
return x ;
}
- public static List<Character> toCharList(String str)
- {
- return str.codePoints().mapToObj(i -> (char) i).map(Character::new)
- .collect(toList());
+ public static List<Character> toCharList(String str) {
+ return str.codePoints().mapToObj(i -> (char) i).map(Character::new)
+ .collect(toList());
}
// ==== Encoding and decoding strings based on a marker character (e.g. %)
// and then the hexadecimal representation of the character.
// Only characters 0-255 can be encoded.
- /** Encode a string using hex values e.g. %20
+ /**
+ * Encode a string using hex values e.g. %20
*
- * @param str String to encode
- * @param marker Marker character
- * @param escapees Characters to encode (must include the marker)
- * @return Encoded string (returns input object if no change)
+ * @param str String to encode
+ * @param marker Marker character
+ * @param escapees Characters to encode (must include the marker)
+ * @return Encoded string (returns input object if no change)
*/
- public static String encodeHex(String str, char marker, char[] escapees)
- {
+ public static String encodeHex(String str, char marker, char[] escapees) {
// We make a first pass to see if there is anything to do.
// This is assuming
// (1) the string is shortish (e.g. fits in L1)
// (2) necessary escaping is not common
-
- int N = str.length();
+
+ int N = str.length() ;
int idx = 0 ;
// Scan stage.
- for ( ; idx < N ; idx++ )
- {
+ for ( ; idx < N ; idx++ ) {
char ch = str.charAt(idx) ;
if ( Chars.charInArray(ch, escapees) )
break ;
@@ -202,72 +183,65 @@ public class StrUtils //extends StringUtils
// At least one char to convert
StringBuilder buff = new StringBuilder() ;
buff.append(str, 0, idx) ; // Insert first part.
- for ( ; idx < N ; idx++ )
- {
+ for ( ; idx < N ; idx++ ) {
char ch = str.charAt(idx) ;
- if ( Chars.charInArray(ch, escapees) )
- {
+ if ( Chars.charInArray(ch, escapees) ) {
Chars.encodeAsHex(buff, marker, ch) ;
continue ;
}
buff.append(ch) ;
}
- return buff.toString();
+ return buff.toString() ;
}
- /** Decode a string using marked hex values e.g. %20
+ /**
+ * Decode a string using marked hex values e.g. %20
*
- * @param str String to decode
- * @param marker The marker charcater
- * @return Decoded string (returns input object on no change)
+ * @param str String to decode
+ * @param marker The marker charcater
+ * @return Decoded string (returns input object on no change)
*/
- public static String decodeHex(String str, char marker)
- {
- int idx = str.indexOf(marker) ;
+ public static String decodeHex(String str, char marker) {
+ int idx = str.indexOf(marker);
if ( idx == -1 )
- return str ;
- StringBuilder buff = new StringBuilder() ;
-
- buff.append(str, 0, idx) ;
- int N = str.length() ;
-
- for ( ; idx < N ; idx++ )
- {
- char ch = str.charAt(idx) ;
+ return str;
+ StringBuilder buff = new StringBuilder();
+
+ buff.append(str, 0, idx);
+ int N = str.length();
+
+ for ( ; idx < N ; idx++ ) {
+ char ch = str.charAt(idx);
// First time through this is true, always.
if ( ch != marker )
- buff.append(ch) ;
- else
- {
- char hi = str.charAt(idx+1) ;
- char lo = str.charAt(idx+2) ; // exceptions.
- char ch2 = (char)(hexDecode(hi)<<4 | hexDecode(lo)) ;
- buff.append(ch2) ;
- idx += 2 ;
+ buff.append(ch);
+ else {
+ char hi = str.charAt(idx + 1);
+ char lo = str.charAt(idx + 2);
+ char ch2 = (char)(hexDecode(hi) << 4 | hexDecode(lo));
+ buff.append(ch2);
+ idx += 2;
}
}
- return buff.toString() ;
+ return buff.toString();
}
-
+
// Encoding is table-driven but for decode, we use code.
static private int hexDecode(char ch) {
- if (ch >= '0' && ch <= '9' )
- return ch - '0' ;
+ if ( ch >= '0' && ch <= '9' )
+ return ch - '0';
if ( ch >= 'A' && ch <= 'F' )
- return ch - 'A' + 10 ;
+ return ch - 'A' + 10;
if ( ch >= 'a' && ch <= 'f' )
- return ch - 'a' + 10 ;
+ return ch - 'a' + 10;
return -1 ;
}
- public static String escapeString(String x)
- {
- return EscapeStr.stringEsc(x) ;
- }
-
- public static String unescapeString(String x)
- {
- return EscapeStr.unescapeStr(x) ;
+ public static String escapeString(String x) {
+ return EscapeStr.stringEsc(x);
}
+ public static String unescapeString(String x) {
+ return EscapeStr.unescapeStr(x);
+ }
}
[2/2] jena git commit: Fix HttpClient handling after JENA-1263.
Posted by an...@apache.org.
Fix HttpClient handling after JENA-1263.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/2cb13230
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/2cb13230
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/2cb13230
Branch: refs/heads/master
Commit: 2cb13230ba5621135867cc4b618cb4e937a45e49
Parents: f01a292
Author: Andy Seaborne <an...@apache.org>
Authored: Mon Dec 19 10:32:39 2016 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Mon Dec 19 10:32:39 2016 +0000
----------------------------------------------------------------------
.../java/org/apache/jena/fuseki/TestAuth.java | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/2cb13230/jena-fuseki1/src/test/java/org/apache/jena/fuseki/TestAuth.java
----------------------------------------------------------------------
diff --git a/jena-fuseki1/src/test/java/org/apache/jena/fuseki/TestAuth.java b/jena-fuseki1/src/test/java/org/apache/jena/fuseki/TestAuth.java
index 27cb936..cc05e4a 100644
--- a/jena-fuseki1/src/test/java/org/apache/jena/fuseki/TestAuth.java
+++ b/jena-fuseki1/src/test/java/org/apache/jena/fuseki/TestAuth.java
@@ -35,7 +35,9 @@ import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.CloseableHttpClient ;
import org.apache.http.impl.client.HttpClients;
+import org.apache.jena.atlas.io.IO ;
import org.apache.jena.atlas.logging.LogCtl ;
import org.apache.jena.atlas.web.HttpException ;
import org.apache.jena.fuseki.server.FusekiConfig ;
@@ -46,7 +48,7 @@ import org.apache.jena.query.DatasetAccessor ;
import org.apache.jena.query.DatasetAccessorFactory ;
import org.apache.jena.query.QueryExecutionFactory ;
import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.riot.web.HttpOp;
+import org.apache.jena.riot.web.HttpOp ;
import org.apache.jena.sparql.core.DatasetGraph ;
import org.apache.jena.sparql.core.DatasetGraphFactory ;
import org.apache.jena.sparql.engine.http.QueryEngineHTTP ;
@@ -57,9 +59,7 @@ import org.apache.jena.sparql.util.Context ;
import org.apache.jena.update.UpdateExecutionFactory ;
import org.apache.jena.update.UpdateFactory ;
import org.apache.jena.update.UpdateRequest ;
-import org.junit.AfterClass ;
-import org.junit.Assert ;
-import org.junit.BeforeClass ;
+import org.junit.* ;
import org.junit.Test ;
/**
@@ -68,13 +68,14 @@ import org.junit.Test ;
public class TestAuth {
// Use different port etc because sometimes the previous testing servers
// don't release ports fast enough (OS issue / Linux)
+
+ private static HttpClient defaultHttpClient;
public static final int authPort = ServerCtl.choosePort() ;
public static final String authUrlRoot = "http://localhost:"+authPort+"/" ;
public static final String authDatasetPath = "/authDataset" ;
public static final String authServiceUpdate = "http://localhost:"+authPort+authDatasetPath+"/update" ;
public static final String authServiceQuery = "http://localhost:"+authPort+authDatasetPath+"/query" ;
public static final String authServiceREST = "http://localhost:"+authPort+authDatasetPath+"/data" ;
-
private static File realmFile;
private static SPARQLServer server;
@@ -85,7 +86,10 @@ public class TestAuth {
*/
@BeforeClass
public static void setup() throws IOException {
- HttpOp.setDefaultHttpClient(null);
+ // Preserve the HttpClient setup.
+ defaultHttpClient = HttpOp.getDefaultHttpClient();
+ HttpOp.setDefaultHttpClient(HttpOp.createPoolingHttpClient()) ;
+
realmFile = File.createTempFile("realm", ".properties");
try(FileWriter writer = new FileWriter(realmFile)) {
@@ -114,6 +118,9 @@ public class TestAuth {
public static void teardown() {
server.stop();
realmFile.delete();
+ // Restore the HttpClient setup.
+ IO.close((CloseableHttpClient) HttpOp.getDefaultHttpClient()) ;
+ HttpOp.setDefaultHttpClient(defaultHttpClient);
}
private static HttpClient withCreds(String uname, String password) {