Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved validateKey function to StringUtils class

Change-Id: I194dc2f7feb59d49579ec5123e21d17bbf3b6ef9
Reviewed-on: http://review.couchbase.org/12139
Reviewed-by: Raghavan N. Srinivas <raghavan.srinivas@gmail.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
  • Loading branch information...
commit 055f40cc7f4c3f5fec0e6b897e582f44015f6fc8 1 parent 7441615
@mikewied mikewied authored mikewied committed
View
24 src/main/java/net/spy/memcached/MemcachedClient.java
@@ -70,6 +70,7 @@
import net.spy.memcached.ops.TimedOutOperationStatus;
import net.spy.memcached.transcoders.TranscodeService;
import net.spy.memcached.transcoders.Transcoder;
+import net.spy.memcached.util.StringUtils;
/**
* Client to a memcached server.
@@ -258,25 +259,6 @@ public NodeLocator getNodeLocator() {
return transcoder;
}
- private void validateKey(String key) {
- byte[] keyBytes = KeyUtil.getKeyBytes(key);
- if (keyBytes.length > MAX_KEY_LENGTH) {
- throw new IllegalArgumentException("Key is too long (maxlen = "
- + MAX_KEY_LENGTH + ")");
- }
- if (keyBytes.length == 0) {
- throw new IllegalArgumentException(
- "Key must contain at least one character.");
- }
- // Validate the key
- for (byte b : keyBytes) {
- if (b == ' ' || b == '\n' || b == '\r' || b == 0) {
- throw new IllegalArgumentException(
- "Key contains invalid characters: ``" + key + "''");
- }
- }
- }
-
/**
* (internal use) Add a raw operation to a numbered connection. This method is
* exposed for testing.
@@ -286,7 +268,7 @@ private void validateKey(String key) {
* @return the Operation
*/
Operation addOp(final String key, final Operation op) {
- validateKey(key);
+ StringUtils.validateKey(key);
mconn.checkState();
mconn.addOperation(key, op);
return op;
@@ -1083,7 +1065,7 @@ public Object get(String key) {
while (keyIter.hasNext() && tcIter.hasNext()) {
String key = keyIter.next();
tcMap.put(key, tcIter.next());
- validateKey(key);
+ StringUtils.validateKey(key);
final MemcachedNode primaryNode = locator.getPrimary(key);
MemcachedNode node = null;
if (primaryNode.isActive()) {
View
22 src/main/java/net/spy/memcached/util/StringUtils.java
@@ -24,6 +24,9 @@
import java.util.Collection;
+import net.spy.memcached.KeyUtil;
+import net.spy.memcached.MemcachedClientIF;
+
/**
* Some String utilities.
*/
@@ -54,4 +57,23 @@ public static boolean isJsonObject(String s) {
return false;
}
}
+
+ public static void validateKey(String key) {
+ byte[] keyBytes = KeyUtil.getKeyBytes(key);
+ if (keyBytes.length > MemcachedClientIF.MAX_KEY_LENGTH) {
+ throw new IllegalArgumentException("Key is too long (maxlen = "
+ + MemcachedClientIF.MAX_KEY_LENGTH + ")");
+ }
+ if (keyBytes.length == 0) {
+ throw new IllegalArgumentException(
+ "Key must contain at least one character.");
+ }
+ // Validate the key
+ for (byte b : keyBytes) {
+ if (b == ' ' || b == '\n' || b == '\r' || b == 0) {
+ throw new IllegalArgumentException(
+ "Key contains invalid characters: ``" + key + "''");
+ }
+ }
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.