You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2014/01/31 19:54:10 UTC
[1/5] git commit: Ensure streams are closed and use utf8 encoding.
Updated Branches:
refs/heads/2292-findbugs d1f139eb4 -> 3bc08e9cf
Ensure streams are closed and use utf8 encoding.
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/0d38c5c3
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/0d38c5c3
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/0d38c5c3
Branch: refs/heads/2292-findbugs
Commit: 0d38c5c3b6c0ef244635d0997543bd04505c8046
Parents: d1f139e
Author: Josh Elser <el...@apache.org>
Authored: Fri Jan 31 12:35:54 2014 -0500
Committer: Josh Elser <el...@apache.org>
Committed: Fri Jan 31 12:35:54 2014 -0500
----------------------------------------------------------------------
.../util/shell/commands/HistoryCommand.java | 33 +++++++++++++-------
1 file changed, 22 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/0d38c5c3/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
index 6de8c39..43dc64f 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
@@ -17,12 +17,16 @@
package org.apache.accumulo.core.util.shell.commands;
import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.util.shell.Shell;
import org.apache.accumulo.core.util.shell.Shell.Command;
import org.apache.commons.cli.CommandLine;
@@ -43,22 +47,25 @@ public class HistoryCommand extends Command {
int counter = 0;
if (cl.hasOption(clearHist.getOpt())) {
-
+ PrintWriter out = null;
try {
-
- final FileWriter outFile = new FileWriter(histDir + "/shell_history.txt");
- final PrintWriter out = new PrintWriter(outFile);
- out.close();
-
- } catch (IOException e) {
-
+ FileOutputStream file = new FileOutputStream(histDir + "/shell_history.txt");
+ final BufferedWriter fileWriter = new BufferedWriter(new OutputStreamWriter(file, Constants.UTF8));
+ out = new PrintWriter(fileWriter);
+ } catch (FileNotFoundException e) {
e.printStackTrace();
+ } finally {
+ // If the file existed, closing the
+ if (null != out) {
+ out.close();
+ }
}
}
else {
+ BufferedReader in = null;
try {
- final BufferedReader in = new BufferedReader(new FileReader(histDir + "/shell_history.txt"));
+ in = new BufferedReader(new InputStreamReader(new FileInputStream(histDir + "/shell_history.txt"), Constants.UTF8));
String Line;
try {
Line = in.readLine();
@@ -74,6 +81,10 @@ public class HistoryCommand extends Command {
} catch (FileNotFoundException e) {
e.printStackTrace();
+ } finally {
+ if (null != in) {
+ in.close();
+ }
}
}
[2/5] git commit: utf8 encoding,
replace unix newlines for system-dependent newlines,
add Serializable to comparator,
and avoid Long/Short constructor use when we have a primitive already.
Posted by el...@apache.org.
utf8 encoding, replace unix newlines for system-dependent newlines, add Serializable to comparator, and avoid Long/Short
constructor use when we have a primitive already.
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/49b86c58
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/49b86c58
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/49b86c58
Branch: refs/heads/2292-findbugs
Commit: 49b86c580f6da92ca48c956d5060a6a0bbd2e8ff
Parents: 0d38c5c
Author: Josh Elser <el...@apache.org>
Authored: Fri Jan 31 12:36:18 2014 -0500
Committer: Josh Elser <el...@apache.org>
Committed: Fri Jan 31 12:36:18 2014 -0500
----------------------------------------------------------------------
.../core/security/ColumnVisibility.java | 38 ++++++++++----------
.../core/security/VisibilityConstraint.java | 5 +--
.../core/security/VisibilityParseException.java | 4 ++-
.../core/trace/InstanceUserPassword.java | 3 +-
.../apache/accumulo/core/trace/SpanTree.java | 2 +-
.../accumulo/core/trace/ZooTraceClient.java | 2 +-
.../core/util/ByteArrayBackedCharSequence.java | 3 +-
.../apache/accumulo/core/util/ByteArraySet.java | 4 ++-
.../accumulo/core/util/ByteBufferUtil.java | 3 +-
.../org/apache/accumulo/core/util/Encoding.java | 5 +--
.../apache/accumulo/core/util/FastFormat.java | 4 ++-
.../org/apache/accumulo/core/util/Merge.java | 2 +-
.../accumulo/core/util/MetadataTable.java | 6 ++--
.../org/apache/accumulo/core/util/TextUtil.java | 2 +-
.../apache/accumulo/core/util/shell/Shell.java | 11 +++---
.../util/shell/commands/AddSplitsCommand.java | 5 +--
.../shell/commands/AuthenticateCommand.java | 3 +-
.../util/shell/commands/CreateTableCommand.java | 5 ++-
.../util/shell/commands/ExecfileCommand.java | 3 +-
.../util/shell/commands/GetSplitsCommand.java | 4 +--
.../core/util/shell/commands/HelpCommand.java | 2 +-
.../core/util/shell/commands/HiddenCommand.java | 3 +-
22 files changed, 69 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java b/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
index 7d7daa2..bd0caba 100644
--- a/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
+++ b/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
@@ -16,6 +16,7 @@
*/
package org.apache.accumulo.core.security;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -113,8 +114,9 @@ public class ColumnVisibility {
}
}
- public static class NodeComparator implements Comparator<Node> {
+ public static class NodeComparator implements Comparator<Node>, Serializable {
+ private static final long serialVersionUID = 1L;
byte[] text;
public NodeComparator(byte[] text) {
@@ -190,7 +192,7 @@ public class ColumnVisibility {
*/
private static void stringify(Node root, byte[] expression, StringBuilder out) {
if (root.type == NodeType.TERM) {
- out.append(new String(expression, root.start, root.end - root.start));
+ out.append(new String(expression, root.start, root.end - root.start, Constants.UTF8));
} else {
String sep = "";
for (Node c : root.children) {
@@ -215,7 +217,7 @@ public class ColumnVisibility {
Node normRoot = normalize(node, expression);
StringBuilder builder = new StringBuilder(expression.length);
stringify(normRoot, expression, builder);
- return builder.toString().getBytes();
+ return builder.toString().getBytes(Constants.UTF8);
}
private static class ColumnVisibilityParser {
@@ -228,10 +230,10 @@ public class ColumnVisibility {
if (expression.length > 0) {
Node node = parse_(expression);
if (node == null) {
- throw new BadArgumentException("operator or missing parens", new String(expression), index - 1);
+ throw new BadArgumentException("operator or missing parens", new String(expression, Constants.UTF8), index - 1);
}
if (parens != 0) {
- throw new BadArgumentException("parenthesis mis-match", new String(expression), index - 1);
+ throw new BadArgumentException("parenthesis mis-match", new String(expression, Constants.UTF8), index - 1);
}
return node;
}
@@ -241,11 +243,11 @@ public class ColumnVisibility {
Node processTerm(int start, int end, Node expr, byte[] expression) {
if (start != end) {
if (expr != null)
- throw new BadArgumentException("expression needs | or &", new String(expression), start);
+ throw new BadArgumentException("expression needs | or &", new String(expression, Constants.UTF8), start);
return new Node(start, end);
}
if (expr == null)
- throw new BadArgumentException("empty term", new String(expression), start);
+ throw new BadArgumentException("empty term", new String(expression, Constants.UTF8), start);
return expr;
}
@@ -261,7 +263,7 @@ public class ColumnVisibility {
expr = processTerm(termStart, index - 1, expr, expression);
if (result != null) {
if (!result.type.equals(NodeType.AND))
- throw new BadArgumentException("cannot mix & and |", new String(expression), index - 1);
+ throw new BadArgumentException("cannot mix & and |", new String(expression, Constants.UTF8), index - 1);
} else {
result = new Node(NodeType.AND);
}
@@ -275,7 +277,7 @@ public class ColumnVisibility {
expr = processTerm(termStart, index - 1, expr, expression);
if (result != null) {
if (!result.type.equals(NodeType.OR))
- throw new BadArgumentException("cannot mix | and &", new String(expression), index - 1);
+ throw new BadArgumentException("cannot mix | and &", new String(expression, Constants.UTF8), index - 1);
} else {
result = new Node(NodeType.OR);
}
@@ -288,7 +290,7 @@ public class ColumnVisibility {
case '(': {
parens++;
if (termStart != index - 1 || expr != null)
- throw new BadArgumentException("expression needs & or |", new String(expression), index - 1);
+ throw new BadArgumentException("expression needs & or |", new String(expression, Constants.UTF8), index - 1);
expr = parse_(expression);
termStart = index;
termComplete = false;
@@ -298,7 +300,7 @@ public class ColumnVisibility {
parens--;
Node child = processTerm(termStart, index - 1, expr, expression);
if (child == null && result == null)
- throw new BadArgumentException("empty expression not allowed", new String(expression), index);
+ throw new BadArgumentException("empty expression not allowed", new String(expression, Constants.UTF8), index);
if (result == null)
return child;
if (result.type == child.type)
@@ -311,22 +313,22 @@ public class ColumnVisibility {
}
case '"': {
if (termStart != index - 1)
- throw new BadArgumentException("expression needs & or |", new String(expression), index - 1);
+ throw new BadArgumentException("expression needs & or |", new String(expression, Constants.UTF8), index - 1);
while (index < expression.length && expression[index] != '"') {
if (expression[index] == '\\') {
index++;
if (expression[index] != '\\' && expression[index] != '"')
- throw new BadArgumentException("invalid escaping within quotes", new String(expression), index - 1);
+ throw new BadArgumentException("invalid escaping within quotes", new String(expression, Constants.UTF8), index - 1);
}
index++;
}
if (index == expression.length)
- throw new BadArgumentException("unclosed quote", new String(expression), termStart);
+ throw new BadArgumentException("unclosed quote", new String(expression, Constants.UTF8), termStart);
if (termStart + 1 == index)
- throw new BadArgumentException("empty term", new String(expression), termStart);
+ throw new BadArgumentException("empty term", new String(expression, Constants.UTF8), termStart);
index++;
@@ -336,11 +338,11 @@ public class ColumnVisibility {
}
default: {
if (termComplete)
- throw new BadArgumentException("expression needs & or |", new String(expression), index - 1);
+ throw new BadArgumentException("expression needs & or |", new String(expression, Constants.UTF8), index - 1);
byte c = expression[index - 1];
if (!Authorizations.isValidAuthChar(c))
- throw new BadArgumentException("bad character (" + c + ")", new String(expression), index - 1);
+ throw new BadArgumentException("bad character (" + c + ")", new String(expression, Constants.UTF8), index - 1);
}
}
}
@@ -351,7 +353,7 @@ public class ColumnVisibility {
result = child;
if (result.type != NodeType.TERM)
if (result.children.size() < 2)
- throw new BadArgumentException("missing term", new String(expression), index);
+ throw new BadArgumentException("missing term", new String(expression, Constants.UTF8), index);
return result;
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/security/VisibilityConstraint.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/security/VisibilityConstraint.java b/core/src/main/java/org/apache/accumulo/core/security/VisibilityConstraint.java
index c8b33ba..94aa1a4 100644
--- a/core/src/main/java/org/apache/accumulo/core/security/VisibilityConstraint.java
+++ b/core/src/main/java/org/apache/accumulo/core/security/VisibilityConstraint.java
@@ -20,6 +20,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.constraints.Constraint;
import org.apache.accumulo.core.data.ColumnUpdate;
import org.apache.accumulo.core.data.Mutation;
@@ -54,7 +55,7 @@ public class VisibilityConstraint implements Constraint {
byte[] cv = update.getColumnVisibility();
if (cv.length > 0) {
String key = null;
- if (ok != null && ok.contains(key = new String(cv)))
+ if (ok != null && ok.contains(key = new String(cv, Constants.UTF8)))
continue;
try {
@@ -63,7 +64,7 @@ public class VisibilityConstraint implements Constraint {
ve = new VisibilityEvaluator(env.getAuthorizations());
if (!ve.evaluate(new ColumnVisibility(cv)))
- return Collections.singletonList(new Short((short) 2));
+ return Collections.singletonList(Short.valueOf((short) 2));
} catch (BadArgumentException bae) {
return Collections.singletonList(new Short((short) 1));
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/security/VisibilityParseException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/security/VisibilityParseException.java b/core/src/main/java/org/apache/accumulo/core/security/VisibilityParseException.java
index 2f46dc9..c61faf5 100644
--- a/core/src/main/java/org/apache/accumulo/core/security/VisibilityParseException.java
+++ b/core/src/main/java/org/apache/accumulo/core/security/VisibilityParseException.java
@@ -18,13 +18,15 @@ package org.apache.accumulo.core.security;
import java.text.ParseException;
+import org.apache.accumulo.core.Constants;
+
public class VisibilityParseException extends ParseException {
private static final long serialVersionUID = 1L;
private String visibility;
public VisibilityParseException(String reason, byte[] visibility, int errorOffset) {
super(reason, errorOffset);
- this.visibility = new String(visibility);
+ this.visibility = new String(visibility, Constants.UTF8);
}
@Override
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/trace/InstanceUserPassword.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/trace/InstanceUserPassword.java b/core/src/main/java/org/apache/accumulo/core/trace/InstanceUserPassword.java
index e9cb439..dfda097 100644
--- a/core/src/main/java/org/apache/accumulo/core/trace/InstanceUserPassword.java
+++ b/core/src/main/java/org/apache/accumulo/core/trace/InstanceUserPassword.java
@@ -16,6 +16,7 @@
*/
package org.apache.accumulo.core.trace;
+import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.Instance;
public class InstanceUserPassword {
@@ -26,6 +27,6 @@ public class InstanceUserPassword {
public InstanceUserPassword(Instance instance, String username, String password) {
this.instance = instance;
this.username = username;
- this.password = password.getBytes();
+ this.password = password.getBytes(Constants.UTF8);
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/trace/SpanTree.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/trace/SpanTree.java b/core/src/main/java/org/apache/accumulo/core/trace/SpanTree.java
index 2a5d72e..772a133 100644
--- a/core/src/main/java/org/apache/accumulo/core/trace/SpanTree.java
+++ b/core/src/main/java/org/apache/accumulo/core/trace/SpanTree.java
@@ -42,7 +42,7 @@ public class SpanTree {
public Set<Long> visit(SpanTreeVisitor visitor) {
Set<Long> visited = new HashSet<Long>();
- List<Long> root = parentChildren.get(new Long(Span.ROOT_SPAN_ID));
+ List<Long> root = parentChildren.get(Long.valueOf(Span.ROOT_SPAN_ID));
if (root == null || root.isEmpty())
return visited;
RemoteSpan rootSpan = nodes.get(root.iterator().next());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java b/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java
index 43fa464..9fd3e22 100644
--- a/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java
+++ b/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java
@@ -73,7 +73,7 @@ public class ZooTraceClient extends SendSpansViaThrift implements Watcher {
List<String> hosts = new ArrayList<String>();
for (String child : children) {
byte[] data = zoo.getData(path + "/" + child, null);
- hosts.add(new String(data));
+ hosts.add(new String(data, Constants.UTF8));
}
this.hosts.clear();
this.hosts.addAll(hosts);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/ByteArrayBackedCharSequence.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/ByteArrayBackedCharSequence.java b/core/src/main/java/org/apache/accumulo/core/util/ByteArrayBackedCharSequence.java
index f64b36c..e7fe974 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/ByteArrayBackedCharSequence.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/ByteArrayBackedCharSequence.java
@@ -16,6 +16,7 @@
*/
package org.apache.accumulo.core.util;
+import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.data.ByteSequence;
public class ByteArrayBackedCharSequence implements CharSequence {
@@ -60,7 +61,7 @@ public class ByteArrayBackedCharSequence implements CharSequence {
}
public String toString() {
- return new String(data, offset, len);
+ return new String(data, offset, len, Constants.UTF8);
}
public void set(ByteSequence bs) {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/ByteArraySet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/ByteArraySet.java b/core/src/main/java/org/apache/accumulo/core/util/ByteArraySet.java
index 68f0ae5..8b71e6f 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/ByteArraySet.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/ByteArraySet.java
@@ -22,6 +22,8 @@ import java.util.Collection;
import java.util.List;
import java.util.TreeSet;
+import org.apache.accumulo.core.Constants;
+
public class ByteArraySet extends TreeSet<byte[]> {
private static final long serialVersionUID = 1L;
@@ -38,7 +40,7 @@ public class ByteArraySet extends TreeSet<byte[]> {
public static ByteArraySet fromStrings(Collection<String> c) {
List<byte[]> lst = new ArrayList<byte[]>();
for (String s : c)
- lst.add(s.getBytes());
+ lst.add(s.getBytes(Constants.UTF8));
return new ByteArraySet(lst);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java b/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java
index 807bc95..01f76b7 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java
@@ -22,6 +22,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
+import org.apache.accumulo.core.Constants;
import org.apache.hadoop.io.Text;
public class ByteBufferUtil {
@@ -60,6 +61,6 @@ public class ByteBufferUtil {
}
public static String toString(ByteBuffer bytes) {
- return new String(bytes.array(), bytes.position(), bytes.remaining());
+ return new String(bytes.array(), bytes.position(), bytes.remaining(), Constants.UTF8);
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/Encoding.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/Encoding.java b/core/src/main/java/org/apache/accumulo/core/util/Encoding.java
index 1c8cb5d..451d4d6 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/Encoding.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/Encoding.java
@@ -16,13 +16,14 @@
*/
package org.apache.accumulo.core.util;
+import org.apache.accumulo.core.Constants;
import org.apache.commons.codec.binary.Base64;
import org.apache.hadoop.io.Text;
public class Encoding {
public static String encodeAsBase64FileName(Text data) {
- String encodedRow = new String(Base64.encodeBase64(TextUtil.getBytes(data)));
+ String encodedRow = new String(Base64.encodeBase64(TextUtil.getBytes(data)), Constants.UTF8);
encodedRow = encodedRow.replace('/', '_').replace('+', '-');
int index = encodedRow.length() - 1;
@@ -39,7 +40,7 @@ public class Encoding {
node = node.replace('_', '/').replace('-', '+');
- return Base64.decodeBase64(node.getBytes());
+ return Base64.decodeBase64(node.getBytes(Constants.UTF8));
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/FastFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/FastFormat.java b/core/src/main/java/org/apache/accumulo/core/util/FastFormat.java
index 496ca95..8c3e416 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/FastFormat.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/FastFormat.java
@@ -16,12 +16,14 @@
*/
package org.apache.accumulo.core.util;
+import org.apache.accumulo.core.Constants;
+
public class FastFormat {
// this 7 to 8 times faster than String.format("%s%06d",prefix, num)
public static byte[] toZeroPaddedString(long num, int width, int radix, byte[] prefix) {
byte ret[] = new byte[width + prefix.length];
if (toZeroPaddedString(ret, 0, num, width, radix, prefix) != ret.length)
- throw new RuntimeException(" Did not format to expected width " + num + " " + width + " " + radix + " " + new String(prefix));
+ throw new RuntimeException(" Did not format to expected width " + num + " " + width + " " + radix + " " + new String(prefix, Constants.UTF8));
return ret;
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/Merge.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/Merge.java b/core/src/main/java/org/apache/accumulo/core/util/Merge.java
index 5ec7a9a..b6cb07f 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/Merge.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/Merge.java
@@ -233,7 +233,7 @@ public class Merge {
Entry<Key,Value> entry = iterator.next();
Key key = entry.getKey();
if (key.getColumnFamily().equals(Constants.METADATA_DATAFILE_COLUMN_FAMILY)) {
- String[] sizeEntries = new String(entry.getValue().get()).split(",");
+ String[] sizeEntries = new String(entry.getValue().get(), Constants.UTF8).split(",");
if (sizeEntries.length == 2) {
tabletSize += Long.parseLong(sizeEntries[0]);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/MetadataTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/MetadataTable.java b/core/src/main/java/org/apache/accumulo/core/util/MetadataTable.java
index e94ef35..fdc7eef 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/MetadataTable.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/MetadataTable.java
@@ -61,7 +61,7 @@ public class MetadataTable {
}
public DataFileValue(byte[] encodedDFV) {
- String[] ba = new String(encodedDFV).split(",");
+ String[] ba = new String(encodedDFV, Constants.UTF8).split(",");
size = Long.parseLong(ba[0]);
numEntries = Long.parseLong(ba[1]);
@@ -90,8 +90,8 @@ public class MetadataTable {
public byte[] encode() {
if (time >= 0)
- return ("" + size + "," + numEntries + "," + time).getBytes();
- return ("" + size + "," + numEntries).getBytes();
+ return ("" + size + "," + numEntries + "," + time).getBytes(Constants.UTF8);
+ return ("" + size + "," + numEntries).getBytes(Constants.UTF8);
}
public boolean equals(Object o) {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java b/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java
index f78747e..45bbe00 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java
@@ -43,7 +43,7 @@ public final class TextUtil {
Text newText = new Text();
newText.append(text.getBytes(), 0, maxLen);
String suffix = "... TRUNCATED";
- newText.append(suffix.getBytes(), 0, suffix.length());
+ newText.append(suffix.getBytes(Constants.UTF8), 0, suffix.length());
return newText;
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
index 7efe5e6..656f2ae 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
@@ -16,9 +16,12 @@
*/
package org.apache.accumulo.core.util.shell;
+import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.util.Arrays;
@@ -437,7 +440,7 @@ public class Shell extends ShellOptions {
ShellCompletor userCompletor = null;
if (execFile != null) {
- java.util.Scanner scanner = new java.util.Scanner(new File(execFile));
+ java.util.Scanner scanner = new java.util.Scanner(new File(execFile), Constants.UTF8.name());
try {
while (scanner.hasNextLine() && !hasExited()) {
execCommand(scanner.nextLine(), true, isVerbose());
@@ -542,7 +545,7 @@ public class Shell extends ShellOptions {
// Obtain the command from the command table
sc = commandFactory.get(command);
if (sc == null) {
- reader.printString(String.format("Unknown command \"%s\". Enter \"help\" for a list possible commands.\n", command));
+ reader.printString(String.format("Unknown command \"%s\". Enter \"help\" for a list possible commands.%n", command));
reader.flushConsole();
return;
}
@@ -805,7 +808,7 @@ public class Shell extends ShellOptions {
PrintWriter writer;
public PrintFile(String filename) throws FileNotFoundException {
- writer = new PrintWriter(filename);
+ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), Constants.UTF8)));
}
@Override
@@ -940,7 +943,7 @@ public class Shell extends ShellOptions {
}
private final void printHelp(String usage, String description, Options opts, int width) {
- PrintWriter pw = new PrintWriter(System.err);
+ PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.err, Constants.UTF8));
new HelpFormatter().printHelp(pw, width, usage, description, opts, 2, 5, null, true);
pw.flush();
if (logErrorsToConsole && writer != null) {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java
index 44cbd35..6bd260c 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java
@@ -19,6 +19,7 @@ package org.apache.accumulo.core.util.shell.commands;
import java.io.File;
import java.util.TreeSet;
+import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.util.shell.Shell;
import org.apache.accumulo.core.util.shell.Shell.Command;
@@ -42,11 +43,11 @@ public class AddSplitsCommand extends Command {
final String f = cl.getOptionValue(optSplitsFile.getOpt());
String line;
- java.util.Scanner file = new java.util.Scanner(new File(f));
+ java.util.Scanner file = new java.util.Scanner(new File(f), Constants.UTF8.name());
while (file.hasNextLine()) {
line = file.nextLine();
if (!line.isEmpty()) {
- splits.add(decode ? new Text(Base64.decodeBase64(line.getBytes())) : new Text(line));
+ splits.add(decode ? new Text(Base64.decodeBase64(line.getBytes(Constants.UTF8))) : new Text(line));
}
}
} else {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java
index ae7854b..5266337 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.Map;
import java.util.Set;
+import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
@@ -37,7 +38,7 @@ public class AuthenticateCommand extends Command {
shellState.getReader().printNewline();
return 0;
} // user canceled
- final byte[] password = p.getBytes();
+ final byte[] password = p.getBytes(Constants.UTF8);
final boolean valid = shellState.getConnector().securityOperations().authenticateUser(user, new PasswordToken(password));
shellState.getReader().printString((valid ? "V" : "Not v") + "alid\n");
return 0;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
index c439909..b476ae4 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
@@ -51,7 +51,6 @@ public class CreateTableCommand extends Command {
private Option createTableOptEVC;
private Option base64Opt;
private Option createTableOptFormatter;
- public static String testTable;
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableExistsException,
TableNotFoundException, IOException, ClassNotFoundException {
@@ -74,12 +73,12 @@ public class CreateTableCommand extends Command {
final String f = cl.getOptionValue(createTableOptSplit.getOpt());
String line;
- Scanner file = new Scanner(new File(f));
+ Scanner file = new Scanner(new File(f), Constants.UTF8.name());
try {
while (file.hasNextLine()) {
line = file.nextLine();
if (!line.isEmpty())
- partitions.add(decode ? new Text(Base64.decodeBase64(line.getBytes())) : new Text(line));
+ partitions.add(decode ? new Text(Base64.decodeBase64(line.getBytes(Constants.UTF8 ))) : new Text(line));
}
} finally {
file.close();
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java
index a9c409f..5fa5b10 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java
@@ -19,6 +19,7 @@ package org.apache.accumulo.core.util.shell.commands;
import java.io.File;
import java.util.Scanner;
+import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.util.shell.Shell;
import org.apache.accumulo.core.util.shell.Shell.Command;
import org.apache.commons.cli.CommandLine;
@@ -35,7 +36,7 @@ public class ExecfileCommand extends Command {
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
- Scanner scanner = new Scanner(new File(cl.getArgs()[0]));
+ Scanner scanner = new Scanner(new File(cl.getArgs()[0]), Constants.UTF8.name());
try {
while (scanner.hasNextLine()) {
shellState.execCommand(scanner.nextLine(), true, cl.hasOption(verboseOption.getOpt()));
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java
index 12c17cb..635d0ff 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java
@@ -99,7 +99,7 @@ public class GetSplitsCommand extends Command {
return null;
}
BinaryFormatter.getlength(text.getLength());
- return encode ? new String(Base64.encodeBase64(TextUtil.getBytes(text))) : BinaryFormatter.appendText(new StringBuilder(), text).toString();
+ return encode ? new String(Base64.encodeBase64(TextUtil.getBytes(text)), Constants.UTF8) : BinaryFormatter.appendText(new StringBuilder(), text).toString();
}
private static String obscuredTabletName(final KeyExtent extent) {
@@ -112,7 +112,7 @@ public class GetSplitsCommand extends Command {
if (extent.getEndRow() != null && extent.getEndRow().getLength() > 0) {
digester.update(extent.getEndRow().getBytes(), 0, extent.getEndRow().getLength());
}
- return new String(Base64.encodeBase64(digester.digest()));
+ return new String(Base64.encodeBase64(digester.digest()), Constants.UTF8);
}
@Override
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
index 1967dce..765fdc4 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
@@ -91,7 +91,7 @@ public class HelpCommand extends Command {
for (String cmd : cl.getArgs()) {
final Command c = shellState.commandFactory.get(cmd);
if (c == null) {
- shellState.getReader().printString(String.format("Unknown command \"%s\". Enter \"help\" for a list possible commands.\n", cmd));
+ shellState.getReader().printString(String.format("Unknown command \"%s\". Enter \"help\" for a list possible commands.%n", cmd));
} else {
c.printHelp(shellState, numColumns);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/49b86c58/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HiddenCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HiddenCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HiddenCommand.java
index 0413d73..37b9ec0 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HiddenCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HiddenCommand.java
@@ -19,6 +19,7 @@ package org.apache.accumulo.core.util.shell.commands;
import java.security.SecureRandom;
import java.util.Random;
+import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.util.shell.Shell;
import org.apache.accumulo.core.util.shell.Shell.Command;
import org.apache.accumulo.core.util.shell.ShellCommandException;
@@ -42,7 +43,7 @@ public class HiddenCommand extends Command {
shellState.getReader().printString(
new String(Base64.decodeBase64(("ICAgICAgIC4tLS4KICAgICAgLyAvXCBcCiAgICAgKCAvLS1cICkKICAgICAuPl8gIF88LgogICAgLyB8ICd8ICcgXAog"
+ "ICAvICB8Xy58Xy4gIFwKICAvIC98ICAgICAgfFwgXAogfCB8IHwgfFwvfCB8IHwgfAogfF98IHwgfCAgfCB8IHxffAogICAgIC8gIF9fICBcCiAgICAvICAv"
- + "ICBcICBcCiAgIC8gIC8gICAgXCAgXF8KIHwvICAvICAgICAgXCB8IHwKIHxfXy8gICAgICAgIFx8X3wK").getBytes())));
+ + "ICBcICBcCiAgIC8gIC8gICAgXCAgXF8KIHwvICAvICAgICAgXCB8IHwKIHxfXy8gICAgICAgIFx8X3wK").getBytes()), Constants.UTF8));
shellState.getReader().printNewline();
} else {
throw new ShellCommandException(ErrorCode.UNRECOGNIZED_COMMAND, getName());
[3/5] git commit: UTF8,
entrySet instead of keySet and removal of an unnecessary static var.
Posted by el...@apache.org.
UTF8, entrySet instead of keySet and removal of an unnecessary static var.
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/049d6cd8
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/049d6cd8
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/049d6cd8
Branch: refs/heads/2292-findbugs
Commit: 049d6cd84bbb11537eae8adac44d3cdd47d9708d
Parents: 49b86c5
Author: Josh Elser <el...@apache.org>
Authored: Fri Jan 31 13:24:11 2014 -0500
Committer: Josh Elser <el...@apache.org>
Committed: Fri Jan 31 13:24:11 2014 -0500
----------------------------------------------------------------------
.../accumulo/core/client/admin/TableOperationsImpl.java | 1 -
.../java/org/apache/accumulo/core/trace/ZooTraceClient.java | 3 ++-
.../accumulo/core/util/shell/commands/ListIterCommand.java | 6 ++++--
.../accumulo/core/util/shell/commands/PasswdCommand.java | 3 ++-
.../core/util/shell/commands/QuotedStringTokenizer.java | 3 ++-
.../accumulo/core/util/shell/commands/SetIterCommand.java | 2 --
.../accumulo/core/util/shell/commands/UserCommand.java | 3 ++-
.../core/util/shell/commands/UserPermissionsCommand.java | 8 ++++----
8 files changed, 16 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/049d6cd8/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
index 307243d..448981b 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
@@ -62,7 +62,6 @@ import org.apache.accumulo.core.client.impl.Tables;
import org.apache.accumulo.core.client.impl.TabletLocator;
import org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation;
import org.apache.accumulo.core.client.impl.thrift.ClientService;
-import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode;
import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
import org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/049d6cd8/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java b/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java
index 9fd3e22..1315a9d 100644
--- a/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java
+++ b/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java
@@ -22,8 +22,9 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
-import org.apache.accumulo.trace.instrument.receivers.SendSpansViaThrift;
+import org.apache.accumulo.core.Constants;
import org.apache.accumulo.fate.zookeeper.ZooReader;
+import org.apache.accumulo.trace.instrument.receivers.SendSpansViaThrift;
import org.apache.log4j.Logger;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/049d6cd8/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java
index 754e033..6001956 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java
@@ -59,8 +59,10 @@ public class ListIterCommand extends Command {
throw new IllegalArgumentException("You must select at least one scope to configure");
}
final StringBuilder sb = new StringBuilder("-\n");
- for (String name : iterators.keySet()) {
- for (IteratorScope scope : iterators.get(name)) {
+ for (Entry<String,EnumSet<IteratorScope>> entry : iterators.entrySet()) {
+ final String name = entry.getKey();
+ final EnumSet<IteratorScope> scopes = entry.getValue();
+ for (IteratorScope scope : scopes) {
if (cl.hasOption(scopeOpts.get(scope).getOpt())) {
IteratorSetting setting = shellState.getConnector().tableOperations().getIteratorSetting(tableName, name, scope);
sb.append("- Iterator ").append(setting.getName()).append(", ").append(scope).append(" scope options:\n");
http://git-wip-us.apache.org/repos/asf/accumulo/blob/049d6cd8/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java
index aba9dd3..7a3be0c 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java
@@ -18,6 +18,7 @@ package org.apache.accumulo.core.util.shell.commands;
import java.io.IOException;
+import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode;
@@ -63,7 +64,7 @@ public class PasswdCommand extends Command {
if (!password.equals(passwordConfirm)) {
throw new IllegalArgumentException("Passwords do not match");
}
- byte[] pass = password.getBytes();
+ byte[] pass = password.getBytes(Constants.UTF8);
shellState.getConnector().securityOperations().changeLocalUserPassword(user, new PasswordToken(pass));
// update the current credentials if the password changed was for
// the current user
http://git-wip-us.apache.org/repos/asf/accumulo/blob/049d6cd8/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuotedStringTokenizer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuotedStringTokenizer.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuotedStringTokenizer.java
index 6872d89..b670d9d 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuotedStringTokenizer.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuotedStringTokenizer.java
@@ -20,6 +20,7 @@ import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator;
+import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.util.BadArgumentException;
import org.apache.accumulo.core.util.shell.Shell;
@@ -57,7 +58,7 @@ public class QuotedStringTokenizer implements Iterable<String> {
final byte[] token = new byte[input.length()];
int tokenLength = 0;
- final byte[] inputBytes = input.getBytes();
+ final byte[] inputBytes = input.getBytes(Constants.UTF8);
for (int i = 0; i < input.length(); ++i) {
final char ch = input.charAt(i);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/049d6cd8/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java
index 26e38e6..7c71e59 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java
@@ -222,8 +222,6 @@ public class SetIterCommand extends Command {
if (input == null) {
reader.printNewline();
throw new IOException("Input stream closed");
- } else {
- input = new String(input);
}
// Places all Parameters and Values into the LocalOptions, even if the value is "".
// This allows us to check for "" values when setting the iterators and allows us to remove
http://git-wip-us.apache.org/repos/asf/accumulo/blob/049d6cd8/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java
index 864b5f3..221beaf 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.Map;
import java.util.Set;
+import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
@@ -43,7 +44,7 @@ public class UserCommand extends Command {
shellState.getReader().printNewline();
return 0;
} // user canceled
- pass = p.getBytes();
+ pass = p.getBytes(Constants.UTF8);
shellState.updateUser(user, new PasswordToken(pass));
return 0;
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/049d6cd8/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserPermissionsCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserPermissionsCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserPermissionsCommand.java
index 8da9742..ce0eed9 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserPermissionsCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserPermissionsCommand.java
@@ -30,7 +30,6 @@ import org.apache.commons.cli.Options;
public class UserPermissionsCommand extends Command {
private Option userOpt;
- private static int runOnce = 0;
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException {
@@ -46,20 +45,21 @@ public class UserPermissionsCommand extends Command {
}
shellState.getReader().printNewline();
+ boolean runOnce = true;
for (String t : shellState.getConnector().tableOperations().list()) {
delim = "";
for (TablePermission p : TablePermission.values()) {
if (shellState.getConnector().securityOperations().hasTablePermission(user, t, p) && p != null) {
- if (runOnce == 0) {
+ if (runOnce) {
shellState.getReader().printString("\nTable permissions (" + t + "): ");
- runOnce++;
+ runOnce = false;
}
shellState.getReader().printString(delim + "Table." + p.name());
delim = ", ";
}
}
- runOnce = 0;
+ runOnce = true;
}
shellState.getReader().printNewline();
return 0;
[5/5] git commit: UTF8, unnecessary object creation (String, Boolean)
Posted by el...@apache.org.
UTF8, unnecessary object creation (String, Boolean)
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/3bc08e9c
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/3bc08e9c
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/3bc08e9c
Branch: refs/heads/2292-findbugs
Commit: 3bc08e9cf0923ea3be5da49f13e8a6c1f19157e4
Parents: e8be283
Author: Josh Elser <el...@apache.org>
Authored: Fri Jan 31 13:52:56 2014 -0500
Committer: Josh Elser <el...@apache.org>
Committed: Fri Jan 31 13:52:56 2014 -0500
----------------------------------------------------------------------
.../java/org/apache/accumulo/fate/AgeOffStore.java | 1 +
.../main/java/org/apache/accumulo/fate/Fate.java | 2 +-
.../java/org/apache/accumulo/fate/ZooStore.java | 14 ++++++++------
.../fate/zookeeper/DistributedReadWriteLock.java | 16 +++++++++-------
.../apache/accumulo/fate/zookeeper/ZooCache.java | 6 ++++--
.../org/apache/accumulo/fate/zookeeper/ZooLock.java | 9 ++++-----
.../accumulo/fate/zookeeper/ZooReservation.java | 16 ++++++++++------
.../apache/accumulo/fate/zookeeper/ZooSession.java | 5 ++++-
8 files changed, 41 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/3bc08e9c/fate/src/main/java/org/apache/accumulo/fate/AgeOffStore.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/AgeOffStore.java b/fate/src/main/java/org/apache/accumulo/fate/AgeOffStore.java
index 3f52e70..f90c3a2 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/AgeOffStore.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/AgeOffStore.java
@@ -126,6 +126,7 @@ public class AgeOffStore<T> implements TStore<T> {
case FAILED:
case SUCCESSFUL:
addCandidate(txid);
+ break;
default:
break;
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/3bc08e9c/fate/src/main/java/org/apache/accumulo/fate/Fate.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/Fate.java b/fate/src/main/java/org/apache/accumulo/fate/Fate.java
index 670154e..9d24b0b 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/Fate.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/Fate.java
@@ -170,7 +170,7 @@ public class Fate<T> {
}
if (autoCleanUp)
- store.setProperty(tid, AUTO_CLEAN_PROP, new Boolean(autoCleanUp));
+ store.setProperty(tid, AUTO_CLEAN_PROP, Boolean.valueOf(autoCleanUp));
store.setProperty(tid, DEBUG_PROP, repo.getDescription());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/3bc08e9c/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java b/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java
index c78dcc1..5fc1858 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.nio.charset.Charset;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Collections;
@@ -44,6 +45,7 @@ import org.apache.zookeeper.KeeperException.NodeExistsException;
//TODO document zookeeper layout - ACCUMULO-1298
public class ZooStore<T> implements TStore<T> {
+ private static final Charset UTF8 = Charset.forName("UTF-8");
private String path;
private IZooReaderWriter zk;
@@ -103,7 +105,7 @@ public class ZooStore<T> implements TStore<T> {
try {
// looking at the code for SecureRandom, it appears to be thread safe
long tid = idgenerator.nextLong() & 0x7fffffffffffffffl;
- zk.putPersistentData(getTXPath(tid), TStatus.NEW.name().getBytes(), NodeExistsPolicy.FAIL);
+ zk.putPersistentData(getTXPath(tid), TStatus.NEW.name().getBytes(UTF8), NodeExistsPolicy.FAIL);
return tid;
} catch (NodeExistsException nee) {
// exist, so just try another random #
@@ -157,7 +159,7 @@ public class ZooStore<T> implements TStore<T> {
// have reserved id, status should not change
try {
- TStatus status = TStatus.valueOf(new String(zk.getData(path + "/" + txdir, null)));
+ TStatus status = TStatus.valueOf(new String(zk.getData(path + "/" + txdir, null), UTF8));
if (status == TStatus.IN_PROGRESS || status == TStatus.FAILED_IN_PROGRESS) {
return tid;
} else {
@@ -319,7 +321,7 @@ public class ZooStore<T> implements TStore<T> {
private TStatus _getStatus(long tid) {
try {
- return TStatus.valueOf(new String(zk.getData(getTXPath(tid), null)));
+ return TStatus.valueOf(new String(zk.getData(getTXPath(tid), null), UTF8));
} catch (NoNodeException nne) {
return TStatus.UNKNOWN;
} catch (Exception e) {
@@ -362,7 +364,7 @@ public class ZooStore<T> implements TStore<T> {
verifyReserved(tid);
try {
- zk.putPersistentData(getTXPath(tid), status.name().getBytes(), NodeExistsPolicy.OVERWRITE);
+ zk.putPersistentData(getTXPath(tid), status.name().getBytes(UTF8), NodeExistsPolicy.OVERWRITE);
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -390,7 +392,7 @@ public class ZooStore<T> implements TStore<T> {
try {
if (so instanceof String) {
- zk.putPersistentData(getTXPath(tid) + "/prop_" + prop, ("S " + so).getBytes(), NodeExistsPolicy.OVERWRITE);
+ zk.putPersistentData(getTXPath(tid) + "/prop_" + prop, ("S " + so).getBytes(UTF8), NodeExistsPolicy.OVERWRITE);
} else {
byte[] sera = serialize(so);
byte[] data = new byte[sera.length + 2];
@@ -416,7 +418,7 @@ public class ZooStore<T> implements TStore<T> {
System.arraycopy(data, 2, sera, 0, sera.length);
return (Serializable) deserialize(sera);
} else if (data[0] == 'S') {
- return new String(data, 2, data.length - 2);
+ return new String(data, 2, data.length - 2, UTF8);
} else {
throw new IllegalStateException("Bad property data " + prop);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/3bc08e9c/fate/src/main/java/org/apache/accumulo/fate/zookeeper/DistributedReadWriteLock.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/DistributedReadWriteLock.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/DistributedReadWriteLock.java
index a9e4f1e..cdf86c0 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/DistributedReadWriteLock.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/DistributedReadWriteLock.java
@@ -16,6 +16,7 @@
*/
package org.apache.accumulo.fate.zookeeper;
+import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Map.Entry;
@@ -31,6 +32,7 @@ import org.apache.log4j.Logger;
// A ReadWriteLock that can be implemented in ZooKeeper. Features the ability to store data
// with the lock, and recover the lock using that data to find the lock.
public class DistributedReadWriteLock implements java.util.concurrent.locks.ReadWriteLock {
+ private static final Charset UTF8 = Charset.forName("UTF-8");
static enum LockType {
READ, WRITE,
@@ -58,7 +60,7 @@ public class DistributedReadWriteLock implements java.util.concurrent.locks.Read
if (split == -1)
throw new IllegalArgumentException();
- this.type = LockType.valueOf(new String(lockData, 0, split));
+ this.type = LockType.valueOf(new String(lockData, 0, split, UTF8));
this.userData = Arrays.copyOfRange(lockData, split + 1, lockData.length);
}
@@ -71,7 +73,7 @@ public class DistributedReadWriteLock implements java.util.concurrent.locks.Read
}
public byte[] getLockData() {
- byte typeBytes[] = type.name().getBytes();
+ byte typeBytes[] = type.name().getBytes(UTF8);
byte[] result = new byte[userData.length + 1 + typeBytes.length];
System.arraycopy(typeBytes, 0, result, 0, typeBytes.length);
result[typeBytes.length] = ':';
@@ -143,7 +145,7 @@ public class DistributedReadWriteLock implements java.util.concurrent.locks.Read
public boolean tryLock() {
if (entry == -1) {
entry = qlock.addEntry(new ParsedLock(this.lockType(), this.userData).getLockData());
- log.info("Added lock entry " + entry + " userData " + new String(this.userData) + " lockType " + lockType());
+ log.info("Added lock entry " + entry + " userData " + new String(this.userData, UTF8) + " lockType " + lockType());
}
SortedMap<Long,byte[]> entries = qlock.getEarlierEntries(entry);
for (Entry<Long,byte[]> entry : entries.entrySet()) {
@@ -153,7 +155,7 @@ public class DistributedReadWriteLock implements java.util.concurrent.locks.Read
if (parsed.type == LockType.WRITE)
return false;
}
- throw new IllegalStateException("Did not find our own lock in the queue: " + this.entry + " userData " + new String(this.userData) + " lockType "
+ throw new IllegalStateException("Did not find our own lock in the queue: " + this.entry + " userData " + new String(this.userData, UTF8) + " lockType "
+ lockType());
}
@@ -175,7 +177,7 @@ public class DistributedReadWriteLock implements java.util.concurrent.locks.Read
public void unlock() {
if (entry == -1)
return;
- log.debug("Removing lock entry " + entry + " userData " + new String(this.userData) + " lockType " + lockType());
+ log.debug("Removing lock entry " + entry + " userData " + new String(this.userData, UTF8) + " lockType " + lockType());
qlock.removeEntry(entry);
entry = -1;
}
@@ -205,12 +207,12 @@ public class DistributedReadWriteLock implements java.util.concurrent.locks.Read
public boolean tryLock() {
if (entry == -1) {
entry = qlock.addEntry(new ParsedLock(this.lockType(), this.userData).getLockData());
- log.info("Added lock entry " + entry + " userData " + new String(this.userData) + " lockType " + lockType());
+ log.info("Added lock entry " + entry + " userData " + new String(this.userData, UTF8) + " lockType " + lockType());
}
SortedMap<Long,byte[]> entries = qlock.getEarlierEntries(entry);
Iterator<Entry<Long,byte[]>> iterator = entries.entrySet().iterator();
if (!iterator.hasNext())
- throw new IllegalStateException("Did not find our own lock in the queue: " + this.entry + " userData " + new String(this.userData) + " lockType "
+ throw new IllegalStateException("Did not find our own lock in the queue: " + this.entry + " userData " + new String(this.userData, UTF8) + " lockType "
+ lockType());
if (iterator.next().getKey().equals(entry))
return true;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/3bc08e9c/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java
index e57b0b6..637c0e2 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java
@@ -21,6 +21,7 @@ import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.nio.charset.Charset;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
@@ -42,6 +43,7 @@ import org.apache.zookeeper.data.Stat;
*/
public class ZooCache {
private static final Logger log = Logger.getLogger(ZooCache.class);
+ private static final Charset UTF8 = Charset.forName("UTF-8");
private ZCacheWatcher watcher = new ZCacheWatcher();
private Watcher externalWatcher = null;
@@ -221,10 +223,10 @@ public class ZooCache {
throw new ConcurrentModificationException();
}
if (log.isTraceEnabled())
- log.trace("zookeeper contained " + zPath + " " + (data == null ? null : new String(data)));
+ log.trace("zookeeper contained " + zPath + " " + (data == null ? null : new String(data, UTF8)));
}
if (log.isTraceEnabled())
- log.trace("putting " + zPath + " " + (data == null ? null : new String(data)) + " in cache");
+ log.trace("putting " + zPath + " " + (data == null ? null : new String(data, UTF8)) + " in cache");
put(zPath, data, stat);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/3bc08e9c/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java
index 8772a83..86c3b88 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java
@@ -16,6 +16,7 @@
*/
package org.apache.accumulo.fate.zookeeper;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -32,7 +33,7 @@ import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
public class ZooLock implements Watcher {
-
+ private static final Charset UTF8 = Charset.forName("UTF-8");
protected static final Logger log = Logger.getLogger(ZooLock.class);
public static final String LOCK_PREFIX = "zlock-";
@@ -346,9 +347,7 @@ public class ZooLock implements Watcher {
watchingParent = false;
if (event.getState() == KeeperState.Expired && lock != null) {
- if (lock != null) {
- lostLock(LockLossReason.SESSION_EXPIRED);
- }
+ lostLock(LockLossReason.SESSION_EXPIRED);
} else {
try { // set the watch on the parent node again
@@ -504,7 +503,7 @@ public class ZooLock implements Watcher {
Stat stat = new Stat();
byte[] data = zk.getData(path + "/" + lockNode, stat);
- if (lockData.equals(new String(data))) {
+ if (lockData.equals(new String(data, UTF8))) {
zk.recursiveDelete(path + "/" + lockNode, stat.getVersion(), NodeMissingPolicy.FAIL);
return true;
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/3bc08e9c/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java
index e938e88..f77260d 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java
@@ -16,6 +16,8 @@
*/
package org.apache.accumulo.fate.zookeeper;
+import java.nio.charset.Charset;
+
import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeExistsPolicy;
import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeMissingPolicy;
import org.apache.log4j.Logger;
@@ -25,6 +27,7 @@ import org.apache.zookeeper.KeeperException.NodeExistsException;
import org.apache.zookeeper.data.Stat;
public class ZooReservation {
+ private static final Charset UTF8 = Charset.forName("UTF-8");
public static boolean attempt(IZooReaderWriter zk, String path, String reservationID, String debugInfo) throws KeeperException, InterruptedException {
if (reservationID.contains(":"))
@@ -32,7 +35,7 @@ public class ZooReservation {
while (true) {
try {
- zk.putPersistentData(path, (reservationID + ":" + debugInfo).getBytes(), NodeExistsPolicy.FAIL);
+ zk.putPersistentData(path, (reservationID + ":" + debugInfo).getBytes(UTF8), NodeExistsPolicy.FAIL);
return true;
} catch (NodeExistsException nee) {
Stat stat = new Stat();
@@ -43,9 +46,9 @@ public class ZooReservation {
continue;
}
- String idInZoo = new String(zooData).split(":")[0];
+ String idInZoo = new String(zooData, UTF8).split(":")[0];
- return idInZoo.equals(new String(reservationID));
+ return idInZoo.equals(reservationID);
}
}
@@ -63,10 +66,11 @@ public class ZooReservation {
return;
}
- String idInZoo = new String(zooData).split(":")[0];
+ String zooDataStr = new String(zooData, UTF8);
+ String idInZoo = zooDataStr.split(":")[0];
- if (!idInZoo.equals(new String(reservationID))) {
- throw new IllegalStateException("Tried to release reservation " + path + " with data mismatch " + new String(reservationID) + " " + new String(zooData));
+ if (!idInZoo.equals(reservationID)) {
+ throw new IllegalStateException("Tried to release reservation " + path + " with data mismatch " + reservationID + " " + zooDataStr);
}
zk.recursiveDelete(path, stat.getVersion(), NodeMissingPolicy.SKIP);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/3bc08e9c/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
index 13f6d08..de9729a 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
@@ -18,8 +18,10 @@ package org.apache.accumulo.fate.zookeeper;
import java.io.IOException;
import java.net.UnknownHostException;
+import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
+
import org.apache.accumulo.fate.util.AddressUtil;
import org.apache.accumulo.fate.util.UtilWaitThread;
import org.apache.log4j.Logger;
@@ -30,6 +32,7 @@ import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooKeeper.States;
public class ZooSession {
+ private static final Charset UTF8 = Charset.forName("UTF-8");
public static class ZooSessionShutdownException extends RuntimeException {
@@ -50,7 +53,7 @@ public class ZooSession {
private static Map<String,ZooSessionInfo> sessions = new HashMap<String,ZooSessionInfo>();
private static String sessionKey(String keepers, int timeout, String scheme, byte[] auth) {
- return keepers + ":" + timeout + ":" + (scheme == null ? "" : scheme) + ":" + (auth == null ? "" : new String(auth));
+ return keepers + ":" + timeout + ":" + (scheme == null ? "" : scheme) + ":" + (auth == null ? "" : new String(auth, UTF8));
}
private static class ZooWatcher implements Watcher {
[4/5] git commit: Remove System.exit's from AdminUtil and lift them
to the Admin class with the main method. Add UTF8 charset to AdminUtil where
necessary.
Posted by el...@apache.org.
Remove System.exit's from AdminUtil and lift them to the Admin class with the main method. Add UTF8 charset to AdminUtil
where necessary.
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/e8be283e
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/e8be283e
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/e8be283e
Branch: refs/heads/2292-findbugs
Commit: e8be283ed65ab8c9f6bb394400fbe4cef84e5a29
Parents: 049d6cd
Author: Josh Elser <el...@apache.org>
Authored: Fri Jan 31 13:25:14 2014 -0500
Committer: Josh Elser <el...@apache.org>
Committed: Fri Jan 31 13:25:14 2014 -0500
----------------------------------------------------------------------
.../org/apache/accumulo/fate/AdminUtil.java | 33 ++++++++++++++------
.../org/apache/accumulo/server/fate/Admin.java | 8 +++--
2 files changed, 29 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/e8be283e/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java b/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java
index bc6874f..0162466 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java
@@ -16,6 +16,7 @@
*/
package org.apache.accumulo.fate;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -33,6 +34,8 @@ import org.apache.zookeeper.KeeperException;
* A utility to administer FATE operations
*/
public class AdminUtil<T> {
+ private static final Charset UTF8 = Charset.forName("UTF-8");
+
public void print(ZooStore<T> zs, IZooReaderWriter zk, String lockPath) throws KeeperException, InterruptedException {
Map<Long,List<String>> heldLocks = new HashMap<Long,List<String>>();
Map<Long,List<String>> waitingLocks = new HashMap<Long,List<String>>();
@@ -51,7 +54,7 @@ public class AdminUtil<T> {
for (String node : lockNodes) {
try {
byte[] data = zk.getData(lockPath + "/" + id + "/" + node, null);
- String lda[] = new String(data).split(":");
+ String lda[] = new String(data, UTF8).split(":");
if (lda[0].charAt(0) == 'W')
sawWriteLock = true;
@@ -129,22 +132,30 @@ public class AdminUtil<T> {
}
}
- public void prepDelete(ZooStore<T> zs, IZooReaderWriter zk, String path, String txidStr) {
- checkGlobalLock(zk, path);
+ public boolean prepDelete(ZooStore<T> zs, IZooReaderWriter zk, String path, String txidStr) {
+ if (!checkGlobalLock(zk, path)) {
+ return false;
+ }
long txid = Long.parseLong(txidStr, 16);
zs.reserve(txid);
zs.delete(txid);
zs.unreserve(txid, 0);
+
+ return true;
}
- public void prepFail(ZooStore<T> zs, IZooReaderWriter zk, String path, String txidStr) {
- checkGlobalLock(zk, path);
+ public boolean prepFail(ZooStore<T> zs, IZooReaderWriter zk, String path, String txidStr) {
+ if (!checkGlobalLock(zk, path)) {
+ return false;
+ }
long txid = Long.parseLong(txidStr, 16);
zs.reserve(txid);
zs.setStatus(txid, TStatus.FAILED_IN_PROGRESS);
zs.unreserve(txid, 0);
+
+ return true;
}
public void deleteLocks(ZooStore<T> zs, IZooReaderWriter zk, String path, String txidStr) throws KeeperException, InterruptedException {
@@ -156,25 +167,27 @@ public class AdminUtil<T> {
for (String node : lockNodes) {
String lockPath = path + "/" + id + "/" + node;
byte[] data = zk.getData(path + "/" + id + "/" + node, null);
- String lda[] = new String(data).split(":");
+ String lda[] = new String(data, UTF8).split(":");
if (lda[1].equals(txidStr))
zk.recursiveDelete(lockPath, NodeMissingPolicy.SKIP);
}
}
}
- public void checkGlobalLock(IZooReaderWriter zk, String path) {
+ public boolean checkGlobalLock(IZooReaderWriter zk, String path) {
try {
if (ZooLock.getLockData(zk.getZooKeeper(), path) != null) {
System.err.println("ERROR: Master lock is held, not running");
- System.exit(-1);
+ return false;
}
} catch (KeeperException e) {
System.err.println("ERROR: Could not read master lock, not running " + e.getMessage());
- System.exit(-1);
+ return false;
} catch (InterruptedException e) {
System.err.println("ERROR: Could not read master lock, not running" + e.getMessage());
- System.exit(-1);
+ return false;
}
+
+ return true;
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/e8be283e/server/src/main/java/org/apache/accumulo/server/fate/Admin.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/fate/Admin.java b/server/src/main/java/org/apache/accumulo/server/fate/Admin.java
index c375981..4a5f0bc 100644
--- a/server/src/main/java/org/apache/accumulo/server/fate/Admin.java
+++ b/server/src/main/java/org/apache/accumulo/server/fate/Admin.java
@@ -79,9 +79,13 @@ public class Admin {
ZooStore<Master> zs = new ZooStore<Master>(path, zk);
if (jc.getParsedCommand().equals("fail")) {
- admin.prepFail(zs, zk, masterPath, args[1]);
+ if (!admin.prepFail(zs, zk, masterPath, args[1])) {
+ System.exit(1);
+ }
} else if (jc.getParsedCommand().equals("delete")) {
- admin.prepDelete(zs, zk, masterPath, args[1]);
+ if (!admin.prepDelete(zs, zk, masterPath, args[1])) {
+ System.exit(1);
+ }
admin.deleteLocks(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS, args[1]);
} else if (jc.getParsedCommand().equals("print")) {
admin.print(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS);