http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/538cfccc/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowHashedTripleResolver.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowHashedTripleResolver.java b/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowHashedTripleResolver.java index 9688fec..5907b5b 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowHashedTripleResolver.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowHashedTripleResolver.java @@ -1,18 +1,3 @@ -package org.apache.rya.api.resolver.triple.impl; - -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTE; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_BYTES; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.codec.binary.Hex; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -21,9 +6,9 @@ import org.apache.commons.codec.binary.Hex; * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -31,11 +16,21 @@ import org.apache.commons.codec.binary.Hex; * specific language governing permissions and limitations * under the License. */ +package org.apache.rya.api.resolver.triple.impl; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTE; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; -import com.google.common.primitives.Bytes; - +import org.apache.commons.codec.binary.Hex; import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; @@ -46,6 +41,8 @@ import org.apache.rya.api.resolver.triple.TripleRow; import org.apache.rya.api.resolver.triple.TripleRowResolver; import org.apache.rya.api.resolver.triple.TripleRowResolverException; +import com.google.common.primitives.Bytes; + /** * Will store triple in spo, po, osp. Storing everything in the whole row. * Date: 7/13/12 @@ -54,33 +51,33 @@ import org.apache.rya.api.resolver.triple.TripleRowResolverException; public class WholeRowHashedTripleResolver implements TripleRowResolver { @Override - public Map<TABLE_LAYOUT, TripleRow> serialize(RyaStatement stmt) throws TripleRowResolverException { + public Map<TABLE_LAYOUT, TripleRow> serialize(final RyaStatement stmt) throws TripleRowResolverException { try { - RyaURI subject = stmt.getSubject(); - RyaURI predicate = stmt.getPredicate(); - RyaType object = stmt.getObject(); - RyaURI context = stmt.getContext(); - Long timestamp = stmt.getTimestamp(); - byte[] columnVisibility = stmt.getColumnVisibility(); - String qualifer = stmt.getQualifer(); - byte[] qualBytes = qualifer == null ? EMPTY_BYTES : qualifer.getBytes(); - byte[] value = stmt.getValue(); + final RyaURI subject = stmt.getSubject(); + final RyaURI predicate = stmt.getPredicate(); + final RyaType object = stmt.getObject(); + final RyaURI context = stmt.getContext(); + final Long timestamp = stmt.getTimestamp(); + final byte[] columnVisibility = stmt.getColumnVisibility(); + final String qualifer = stmt.getQualifer(); + final byte[] qualBytes = qualifer == null ? EMPTY_BYTES : qualifer.getBytes(StandardCharsets.UTF_8); + final byte[] value = stmt.getValue(); assert subject != null && predicate != null && object != null; - byte[] cf = (context == null) ? EMPTY_BYTES : context.getData().getBytes(); - Map<TABLE_LAYOUT, TripleRow> tripleRowMap = new HashMap<TABLE_LAYOUT, TripleRow>(); - MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] subjBytes = subject.getData().getBytes(); - byte[] subjHashBytes = md.digest(subjBytes); - byte[] predBytes = predicate.getData().getBytes(); - byte[] predHashBytes = md.digest(predBytes); - byte[][] objBytes = RyaContext.getInstance().serializeType(object); + final byte[] cf = (context == null) ? EMPTY_BYTES : context.getData().getBytes(StandardCharsets.UTF_8); + final Map<TABLE_LAYOUT, TripleRow> tripleRowMap = new HashMap<TABLE_LAYOUT, TripleRow>(); + final MessageDigest md = MessageDigest.getInstance("MD5"); + final byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8); + final byte[] subjHashBytes = md.digest(subjBytes); + final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8); + final byte[] predHashBytes = md.digest(predBytes); + final byte[][] objBytes = RyaContext.getInstance().serializeType(object); tripleRowMap.put(TABLE_LAYOUT.SPO, - new TripleRow(Bytes.concat(Hex.encodeHexString(subjHashBytes).getBytes(), DELIM_BYTES, subjBytes, DELIM_BYTES, + new TripleRow(Bytes.concat(Hex.encodeHexString(subjHashBytes).getBytes(StandardCharsets.UTF_8), DELIM_BYTES, subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes[0], objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value)); tripleRowMap.put(TABLE_LAYOUT.PO, - new TripleRow(Bytes.concat(Hex.encodeHexString(predHashBytes).getBytes(), DELIM_BYTES, predBytes, DELIM_BYTES, + new TripleRow(Bytes.concat(Hex.encodeHexString(predHashBytes).getBytes(StandardCharsets.UTF_8), DELIM_BYTES, predBytes, DELIM_BYTES, objBytes[0], DELIM_BYTES, subjBytes, objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value)); @@ -90,68 +87,68 @@ public class WholeRowHashedTripleResolver implements TripleRowResolver { predBytes, objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value)); return tripleRowMap; - } catch (RyaTypeResolverException e) { + } catch (final RyaTypeResolverException e) { throw new TripleRowResolverException(e); - } catch (NoSuchAlgorithmException e) { + } catch (final NoSuchAlgorithmException e) { throw new TripleRowResolverException(e); } } @Override - public RyaStatement deserialize(TABLE_LAYOUT table_layout, TripleRow tripleRow) throws TripleRowResolverException { + public RyaStatement deserialize(final TABLE_LAYOUT table_layout, final TripleRow tripleRow) throws TripleRowResolverException { try { assert tripleRow != null && table_layout != null; byte[] row = tripleRow.getRow(); - + // if it is a hashed row, ony keep the row after the hash if ((table_layout == TABLE_LAYOUT.SPO) || (table_layout == TABLE_LAYOUT.PO)) { - int hashStart = Bytes.indexOf(row, DELIM_BYTE); + final int hashStart = Bytes.indexOf(row, DELIM_BYTE); row = Arrays.copyOfRange(row, hashStart + 1, row.length); } - - int firstIndex = Bytes.indexOf(row, DELIM_BYTE); - byte[] first= Arrays.copyOf(row, firstIndex); - int secondIndex = Bytes.lastIndexOf(row, DELIM_BYTE); - int typeIndex = Bytes.indexOf(row, TYPE_DELIM_BYTE); - byte[] second = Arrays.copyOfRange(row, firstIndex + 1, secondIndex); - byte[] third = Arrays.copyOfRange(row, secondIndex + 1, typeIndex); - byte[] type = Arrays.copyOfRange(row, typeIndex, row.length); - byte[] columnFamily = tripleRow.getColumnFamily(); - boolean contextExists = columnFamily != null && columnFamily.length > 0; - RyaURI context = (contextExists) ? (new RyaURI(new String(columnFamily))) : null; - byte[] columnQualifier = tripleRow.getColumnQualifier(); - String qualifier = columnQualifier != null && columnQualifier.length > 0 ? new String(columnQualifier) : null; - Long timestamp = tripleRow.getTimestamp(); - byte[] columnVisibility = tripleRow.getColumnVisibility(); - byte[] value = tripleRow.getValue(); + + final int firstIndex = Bytes.indexOf(row, DELIM_BYTE); + final byte[] first= Arrays.copyOf(row, firstIndex); + final int secondIndex = Bytes.lastIndexOf(row, DELIM_BYTE); + final int typeIndex = Bytes.indexOf(row, TYPE_DELIM_BYTE); + final byte[] second = Arrays.copyOfRange(row, firstIndex + 1, secondIndex); + final byte[] third = Arrays.copyOfRange(row, secondIndex + 1, typeIndex); + final byte[] type = Arrays.copyOfRange(row, typeIndex, row.length); + final byte[] columnFamily = tripleRow.getColumnFamily(); + final boolean contextExists = columnFamily != null && columnFamily.length > 0; + final RyaURI context = (contextExists) ? (new RyaURI(new String(columnFamily, StandardCharsets.UTF_8))) : null; + final byte[] columnQualifier = tripleRow.getColumnQualifier(); + final String qualifier = columnQualifier != null && columnQualifier.length > 0 ? new String(columnQualifier, StandardCharsets.UTF_8) : null; + final Long timestamp = tripleRow.getTimestamp(); + final byte[] columnVisibility = tripleRow.getColumnVisibility(); + final byte[] value = tripleRow.getValue(); switch (table_layout) { case SPO: { - byte[] obj = Bytes.concat(third, type); + final byte[] obj = Bytes.concat(third, type); return new RyaStatement( - new RyaURI(new String(first)), - new RyaURI(new String(second)), + new RyaURI(new String(first, StandardCharsets.UTF_8)), + new RyaURI(new String(second, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp); } case PO: { - byte[] obj = Bytes.concat(second, type); + final byte[] obj = Bytes.concat(second, type); return new RyaStatement( - new RyaURI(new String(third)), - new RyaURI(new String(first)), + new RyaURI(new String(third, StandardCharsets.UTF_8)), + new RyaURI(new String(first, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp); } case OSP: { - byte[] obj = Bytes.concat(first, type); + final byte[] obj = Bytes.concat(first, type); return new RyaStatement( - new RyaURI(new String(second)), - new RyaURI(new String(third)), + new RyaURI(new String(second, StandardCharsets.UTF_8)), + new RyaURI(new String(third, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp); } } - } catch (RyaTypeResolverException e) { + } catch (final RyaTypeResolverException e) { throw new TripleRowResolverException(e); } throw new TripleRowResolverException("TripleRow[" + tripleRow + "] with Table layout[" + table_layout + "] is not deserializable");
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/538cfccc/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowTripleResolver.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowTripleResolver.java b/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowTripleResolver.java index 792d02e..cbd65b6 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowTripleResolver.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/resolver/triple/impl/WholeRowTripleResolver.java @@ -1,5 +1,3 @@ -package org.apache.rya.api.resolver.triple.impl; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -8,9 +6,9 @@ package org.apache.rya.api.resolver.triple.impl; * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -18,10 +16,19 @@ package org.apache.rya.api.resolver.triple.impl; * specific language governing permissions and limitations * under the License. */ +package org.apache.rya.api.resolver.triple.impl; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTE; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_BYTES; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; -import com.google.common.primitives.Bytes; +import org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaURI; @@ -31,11 +38,7 @@ import org.apache.rya.api.resolver.triple.TripleRow; import org.apache.rya.api.resolver.triple.TripleRowResolver; import org.apache.rya.api.resolver.triple.TripleRowResolverException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import static org.apache.rya.api.RdfCloudTripleStoreConstants.*; +import com.google.common.primitives.Bytes; /** * Will store triple in spo, po, osp. Storing everything in the whole row. @@ -45,23 +48,23 @@ import static org.apache.rya.api.RdfCloudTripleStoreConstants.*; public class WholeRowTripleResolver implements TripleRowResolver { @Override - public Map<TABLE_LAYOUT, TripleRow> serialize(RyaStatement stmt) throws TripleRowResolverException { + public Map<TABLE_LAYOUT, TripleRow> serialize(final RyaStatement stmt) throws TripleRowResolverException { try { - RyaURI subject = stmt.getSubject(); - RyaURI predicate = stmt.getPredicate(); - RyaType object = stmt.getObject(); - RyaURI context = stmt.getContext(); - Long timestamp = stmt.getTimestamp(); - byte[] columnVisibility = stmt.getColumnVisibility(); - String qualifer = stmt.getQualifer(); - byte[] qualBytes = qualifer == null ? EMPTY_BYTES : qualifer.getBytes(); - byte[] value = stmt.getValue(); + final RyaURI subject = stmt.getSubject(); + final RyaURI predicate = stmt.getPredicate(); + final RyaType object = stmt.getObject(); + final RyaURI context = stmt.getContext(); + final Long timestamp = stmt.getTimestamp(); + final byte[] columnVisibility = stmt.getColumnVisibility(); + final String qualifer = stmt.getQualifer(); + final byte[] qualBytes = qualifer == null ? EMPTY_BYTES : qualifer.getBytes(StandardCharsets.UTF_8); + final byte[] value = stmt.getValue(); assert subject != null && predicate != null && object != null; - byte[] cf = (context == null) ? EMPTY_BYTES : context.getData().getBytes(); - Map<TABLE_LAYOUT, TripleRow> tripleRowMap = new HashMap<TABLE_LAYOUT, TripleRow>(); - byte[] subjBytes = subject.getData().getBytes(); - byte[] predBytes = predicate.getData().getBytes(); - byte[][] objBytes = RyaContext.getInstance().serializeType(object); + final byte[] cf = (context == null) ? EMPTY_BYTES : context.getData().getBytes(StandardCharsets.UTF_8); + final Map<TABLE_LAYOUT, TripleRow> tripleRowMap = new HashMap<TABLE_LAYOUT, TripleRow>(); + final byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8); + final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8); + final byte[][] objBytes = RyaContext.getInstance().serializeType(object); tripleRowMap.put(TABLE_LAYOUT.SPO, new TripleRow(Bytes.concat(subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, @@ -78,59 +81,59 @@ public class WholeRowTripleResolver implements TripleRowResolver { predBytes, objBytes[1]), cf, qualBytes, timestamp, columnVisibility, value)); return tripleRowMap; - } catch (RyaTypeResolverException e) { + } catch (final RyaTypeResolverException e) { throw new TripleRowResolverException(e); } } @Override - public RyaStatement deserialize(TABLE_LAYOUT table_layout, TripleRow tripleRow) throws TripleRowResolverException { + public RyaStatement deserialize(final TABLE_LAYOUT table_layout, final TripleRow tripleRow) throws TripleRowResolverException { try { assert tripleRow != null && table_layout != null; - byte[] row = tripleRow.getRow(); - int firstIndex = Bytes.indexOf(row, DELIM_BYTE); - int secondIndex = Bytes.lastIndexOf(row, DELIM_BYTE); - int typeIndex = Bytes.indexOf(row, TYPE_DELIM_BYTE); - byte[] first = Arrays.copyOf(row, firstIndex); - byte[] second = Arrays.copyOfRange(row, firstIndex + 1, secondIndex); - byte[] third = Arrays.copyOfRange(row, secondIndex + 1, typeIndex); - byte[] type = Arrays.copyOfRange(row, typeIndex, row.length); - byte[] columnFamily = tripleRow.getColumnFamily(); - boolean contextExists = columnFamily != null && columnFamily.length > 0; - RyaURI context = (contextExists) ? (new RyaURI(new String(columnFamily))) : null; - byte[] columnQualifier = tripleRow.getColumnQualifier(); - String qualifier = columnQualifier != null && columnQualifier.length > 0 ? new String(columnQualifier) : null; - Long timestamp = tripleRow.getTimestamp(); - byte[] columnVisibility = tripleRow.getColumnVisibility(); - byte[] value = tripleRow.getValue(); + final byte[] row = tripleRow.getRow(); + final int firstIndex = Bytes.indexOf(row, DELIM_BYTE); + final int secondIndex = Bytes.lastIndexOf(row, DELIM_BYTE); + final int typeIndex = Bytes.indexOf(row, TYPE_DELIM_BYTE); + final byte[] first = Arrays.copyOf(row, firstIndex); + final byte[] second = Arrays.copyOfRange(row, firstIndex + 1, secondIndex); + final byte[] third = Arrays.copyOfRange(row, secondIndex + 1, typeIndex); + final byte[] type = Arrays.copyOfRange(row, typeIndex, row.length); + final byte[] columnFamily = tripleRow.getColumnFamily(); + final boolean contextExists = columnFamily != null && columnFamily.length > 0; + final RyaURI context = (contextExists) ? (new RyaURI(new String(columnFamily, StandardCharsets.UTF_8))) : null; + final byte[] columnQualifier = tripleRow.getColumnQualifier(); + final String qualifier = columnQualifier != null && columnQualifier.length > 0 ? new String(columnQualifier, StandardCharsets.UTF_8) : null; + final Long timestamp = tripleRow.getTimestamp(); + final byte[] columnVisibility = tripleRow.getColumnVisibility(); + final byte[] value = tripleRow.getValue(); switch (table_layout) { case SPO: { - byte[] obj = Bytes.concat(third, type); + final byte[] obj = Bytes.concat(third, type); return new RyaStatement( - new RyaURI(new String(first)), - new RyaURI(new String(second)), + new RyaURI(new String(first, StandardCharsets.UTF_8)), + new RyaURI(new String(second, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp); } case PO: { - byte[] obj = Bytes.concat(second, type); + final byte[] obj = Bytes.concat(second, type); return new RyaStatement( - new RyaURI(new String(third)), - new RyaURI(new String(first)), + new RyaURI(new String(third, StandardCharsets.UTF_8)), + new RyaURI(new String(first, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp); } case OSP: { - byte[] obj = Bytes.concat(first, type); + final byte[] obj = Bytes.concat(first, type); return new RyaStatement( - new RyaURI(new String(second)), - new RyaURI(new String(third)), + new RyaURI(new String(second, StandardCharsets.UTF_8)), + new RyaURI(new String(third, StandardCharsets.UTF_8)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp); } } - } catch (RyaTypeResolverException e) { + } catch (final RyaTypeResolverException e) { throw new TripleRowResolverException(e); } throw new TripleRowResolverException("TripleRow[" + tripleRow + "] with Table layout[" + table_layout + "] is not deserializable"); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/538cfccc/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloNamespaceTableIterator.java ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloNamespaceTableIterator.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloNamespaceTableIterator.java index 0f1fd3d..9f6c1dd 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloNamespaceTableIterator.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloNamespaceTableIterator.java @@ -1,5 +1,3 @@ -package org.apache.rya.accumulo; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -8,9 +6,9 @@ package org.apache.rya.accumulo; * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -18,28 +16,30 @@ package org.apache.rya.accumulo; * specific language governing permissions and limitations * under the License. */ +package org.apache.rya.accumulo; +import java.io.IOError; +import java.nio.charset.StandardCharsets; +import java.util.Iterator; +import java.util.Map.Entry; - -import com.google.common.base.Preconditions; -import info.aduna.iteration.CloseableIteration; -import org.apache.rya.api.persist.RdfDAOException; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Value; +import org.apache.rya.api.persist.RdfDAOException; import org.openrdf.model.Namespace; import org.openrdf.model.impl.NamespaceImpl; -import java.io.IOError; -import java.util.Iterator; -import java.util.Map.Entry; +import com.google.common.base.Preconditions; + +import info.aduna.iteration.CloseableIteration; public class AccumuloNamespaceTableIterator<T extends Namespace> implements CloseableIteration<Namespace, RdfDAOException> { private boolean open = false; - private Iterator<Entry<Key, Value>> result; + private final Iterator<Entry<Key, Value>> result; - public AccumuloNamespaceTableIterator(Iterator<Entry<Key, Value>> result) throws RdfDAOException { + public AccumuloNamespaceTableIterator(final Iterator<Entry<Key, Value>> result) throws RdfDAOException { Preconditions.checkNotNull(result); open = true; this.result = result; @@ -50,7 +50,7 @@ public class AccumuloNamespaceTableIterator<T extends Namespace> implements try { verifyIsOpen(); open = false; - } catch (IOError e) { + } catch (final IOError e) { throw new RdfDAOException(e); } } @@ -75,15 +75,15 @@ public class AccumuloNamespaceTableIterator<T extends Namespace> implements return null; } - public static Namespace getNamespace(Iterator<Entry<Key, Value>> rowResults) { + public static Namespace getNamespace(final Iterator<Entry<Key, Value>> rowResults) { for (; rowResults.hasNext(); ) { - Entry<Key, Value> next = rowResults.next(); - Key key = next.getKey(); - Value val = next.getValue(); - String cf = key.getColumnFamily().toString(); - String cq = key.getColumnQualifier().toString(); - return new NamespaceImpl(key.getRow().toString(), new String( - val.get())); + final Entry<Key, Value> next = rowResults.next(); + final Key key = next.getKey(); + final Value val = next.getValue(); + final String cf = key.getColumnFamily().toString(); + final String cq = key.getColumnQualifier().toString(); + return new NamespaceImpl(key.getRow().toString(), + new String(val.get(), StandardCharsets.UTF_8)); } return null; } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/538cfccc/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfEvalStatsDAO.java ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfEvalStatsDAO.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfEvalStatsDAO.java index 10584c5..f47b4b3 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfEvalStatsDAO.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfEvalStatsDAO.java @@ -1,5 +1,3 @@ -package org.apache.rya.accumulo; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -8,9 +6,9 @@ package org.apache.rya.accumulo; * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -18,29 +16,24 @@ package org.apache.rya.accumulo; * specific language governing permissions and limitations * under the License. */ - - +package org.apache.rya.accumulo; import static com.google.common.base.Preconditions.checkNotNull; import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM; import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_TEXT; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.PRED_CF_TXT; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.SUBJECT_CF_TXT; -import static org.apache.rya.api.RdfCloudTripleStoreConstants.SUBJECTPRED_CF_TXT; import static org.apache.rya.api.RdfCloudTripleStoreConstants.PREDOBJECT_CF_TXT; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.PRED_CF_TXT; import static org.apache.rya.api.RdfCloudTripleStoreConstants.SUBJECTOBJECT_CF_TXT; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.SUBJECTPRED_CF_TXT; +import static org.apache.rya.api.RdfCloudTripleStoreConstants.SUBJECT_CF_TXT; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; -import org.apache.rya.api.RdfCloudTripleStoreStatement; -import org.apache.rya.api.layout.TableLayoutStrategy; -import org.apache.rya.api.persist.RdfDAOException; -import org.apache.rya.api.persist.RdfEvalStatsDAO; - import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.Scanner; import org.apache.accumulo.core.client.admin.TableOperations; @@ -48,11 +41,15 @@ import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.security.Authorizations; import org.apache.hadoop.io.Text; +import org.apache.rya.api.RdfCloudTripleStoreStatement; +import org.apache.rya.api.layout.TableLayoutStrategy; +import org.apache.rya.api.persist.RdfDAOException; +import org.apache.rya.api.persist.RdfEvalStatsDAO; import org.openrdf.model.Resource; import org.openrdf.model.Value; /** - * Class CloudbaseRdfEvalStatsDAO + * Class AccumuloRdfEvalStatsDAO * Date: Feb 28, 2012 * Time: 5:03:16 PM */ @@ -61,7 +58,7 @@ public class AccumuloRdfEvalStatsDAO implements RdfEvalStatsDAO<AccumuloRdfConfi private boolean initialized = false; private AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(); - private Collection<RdfCloudTripleStoreStatement> statements = new ArrayList<RdfCloudTripleStoreStatement>(); + private final Collection<RdfCloudTripleStoreStatement> statements = new ArrayList<RdfCloudTripleStoreStatement>(); private Connector connector; // private String evalTable = TBL_EVAL; @@ -78,18 +75,18 @@ public class AccumuloRdfEvalStatsDAO implements RdfEvalStatsDAO<AccumuloRdfConfi // evalTable = conf.get(RdfCloudTripleStoreConfiguration.CONF_TBL_EVAL, evalTable); // conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_EVAL, evalTable); - TableOperations tos = connector.tableOperations(); + final TableOperations tos = connector.tableOperations(); AccumuloRdfUtils.createTableIfNotExist(tos, tableLayoutStrategy.getEval()); // boolean tableExists = tos.exists(evalTable); // if (!tableExists) // tos.create(evalTable); initialized = true; - } catch (Exception e) { + } catch (final Exception e) { throw new RdfDAOException(e); } } - + @Override public void destroy() throws RdfDAOException { if (!isInitialized()) { @@ -107,25 +104,27 @@ public class AccumuloRdfEvalStatsDAO implements RdfEvalStatsDAO<AccumuloRdfConfi return connector; } - public void setConnector(Connector connector) { + public void setConnector(final Connector connector) { this.connector = connector; } + @Override public AccumuloRdfConfiguration getConf() { return conf; } - public void setConf(AccumuloRdfConfiguration conf) { + @Override + public void setConf(final AccumuloRdfConfiguration conf) { this.conf = conf; } - @Override - public double getCardinality(AccumuloRdfConfiguration conf, - org.apache.rya.api.persist.RdfEvalStatsDAO.CARDINALITY_OF card, - List<Value> val, Resource context) throws RdfDAOException { + @Override + public double getCardinality(final AccumuloRdfConfiguration conf, + final org.apache.rya.api.persist.RdfEvalStatsDAO.CARDINALITY_OF card, final List<Value> val, + final Resource context) throws RdfDAOException { try { - Authorizations authorizations = conf.getAuthorizations(); - Scanner scanner = connector.createScanner(tableLayoutStrategy.getEval(), authorizations); + final Authorizations authorizations = conf.getAuthorizations(); + final Scanner scanner = connector.createScanner(tableLayoutStrategy.getEval(), authorizations); Text cfTxt = null; if (CARDINALITY_OF.SUBJECT.equals(card)) { cfTxt = SUBJECT_CF_TXT; @@ -140,34 +139,36 @@ public class AccumuloRdfEvalStatsDAO implements RdfEvalStatsDAO<AccumuloRdfConfi cfTxt = SUBJECTPRED_CF_TXT; } else if (CARDINALITY_OF.PREDICATEOBJECT.equals(card)) { cfTxt = PREDOBJECT_CF_TXT; - } else throw new IllegalArgumentException("Not right Cardinality[" + card + "]"); + } else { + throw new IllegalArgumentException("Not right Cardinality[" + card + "]"); + } Text cq = EMPTY_TEXT; if (context != null) { - cq = new Text(context.stringValue().getBytes()); + cq = new Text(context.stringValue().getBytes(StandardCharsets.UTF_8)); } scanner.fetchColumn(cfTxt, cq); - Iterator<Value> vals = val.iterator(); + final Iterator<Value> vals = val.iterator(); String compositeIndex = vals.next().stringValue(); while (vals.hasNext()){ compositeIndex += DELIM + vals.next().stringValue(); } - scanner.setRange(new Range(new Text(compositeIndex.getBytes()))); - Iterator<Map.Entry<Key, org.apache.accumulo.core.data.Value>> iter = scanner.iterator(); + scanner.setRange(new Range(new Text(compositeIndex.getBytes(StandardCharsets.UTF_8)))); + final Iterator<Map.Entry<Key, org.apache.accumulo.core.data.Value>> iter = scanner.iterator(); if (iter.hasNext()) { - return Double.parseDouble(new String(iter.next().getValue().get())); + return Double.parseDouble(new String(iter.next().getValue().get(), StandardCharsets.UTF_8)); } - } catch (Exception e) { + } catch (final Exception e) { throw new RdfDAOException(e); } //default return -1; - } - - @Override - public double getCardinality(AccumuloRdfConfiguration conf, - org.apache.rya.api.persist.RdfEvalStatsDAO.CARDINALITY_OF card, - List<Value> val) throws RdfDAOException { - return getCardinality(conf, card, val, null); - } + } + + @Override + public double getCardinality(final AccumuloRdfConfiguration conf, + final org.apache.rya.api.persist.RdfEvalStatsDAO.CARDINALITY_OF card, final List<Value> val) + throws RdfDAOException { + return getCardinality(conf, card, val, null); + } } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/538cfccc/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRyaDAO.java ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRyaDAO.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRyaDAO.java index f1f7c03..8c99e44 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRyaDAO.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRyaDAO.java @@ -1,5 +1,3 @@ -package org.apache.rya.accumulo; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,8 +16,7 @@ package org.apache.rya.accumulo; * specific language governing permissions and limitations * under the License. */ - - +package org.apache.rya.accumulo; import static com.google.common.base.Preconditions.checkNotNull; import static org.apache.rya.accumulo.AccumuloRdfConstants.ALL_AUTHORIZATIONS; @@ -33,6 +30,7 @@ import static org.apache.rya.api.RdfCloudTripleStoreConstants.RTS_VERSION_PREDIC import static org.apache.rya.api.RdfCloudTripleStoreConstants.VERSION_RYA; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Collections; import java.util.Iterator; @@ -319,7 +317,7 @@ public class AccumuloRyaDAO implements RyaDAO<AccumuloRdfConfiguration>, RyaName public void addNamespace(final String pfx, final String namespace) throws RyaDAOException { try { final Mutation m = new Mutation(new Text(pfx)); - m.put(INFO_NAMESPACE_TXT, EMPTY_TEXT, new Value(namespace.getBytes())); + m.put(INFO_NAMESPACE_TXT, EMPTY_TEXT, new Value(namespace.getBytes(StandardCharsets.UTF_8))); bw_ns.addMutation(m); if (flushEachUpdate) { mt_bw.flush(); } } catch (final Exception e) { @@ -338,7 +336,7 @@ public class AccumuloRyaDAO implements RyaDAO<AccumuloRdfConfiguration>, RyaName .iterator(); if (iterator.hasNext()) { - return new String(iterator.next().getValue().get()); + return new String(iterator.next().getValue().get(), StandardCharsets.UTF_8); } } catch (final Exception e) { throw new RyaDAOException(e); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/538cfccc/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBNamespaceManager.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBNamespaceManager.java b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBNamespaceManager.java index d2d6d7e..6956f49 100644 --- a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBNamespaceManager.java +++ b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBNamespaceManager.java @@ -1,5 +1,3 @@ -package org.apache.rya.mongodb.dao; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -8,9 +6,9 @@ package org.apache.rya.mongodb.dao; * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -18,18 +16,16 @@ package org.apache.rya.mongodb.dao; * specific language governing permissions and limitations * under the License. */ +package org.apache.rya.mongodb.dao; - -import info.aduna.iteration.CloseableIteration; - +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Map; +import org.apache.commons.codec.binary.Hex; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.mongodb.MongoDBRdfConfiguration; - -import org.apache.commons.codec.binary.Hex; import org.openrdf.model.Namespace; import com.mongodb.BasicDBObject; @@ -37,22 +33,28 @@ import com.mongodb.DBCollection; import com.mongodb.DBCursor; import com.mongodb.DBObject; +import info.aduna.iteration.CloseableIteration; + public class SimpleMongoDBNamespaceManager implements MongoDBNamespaceManager { public class NamespaceImplementation implements Namespace { - private String namespace; - private String prefix; + private final String namespace; + private final String prefix; - public NamespaceImplementation(String namespace, String prefix) { + public NamespaceImplementation(final String namespace, final String prefix) { this.namespace = namespace; this.prefix = prefix; } @Override - public int compareTo(Namespace o) { - if (!namespace.equalsIgnoreCase(o.getName())) return namespace.compareTo(o.getName()); - if (!prefix.equalsIgnoreCase(o.getPrefix())) return prefix.compareTo(o.getPrefix()); + public int compareTo(final Namespace o) { + if (!namespace.equalsIgnoreCase(o.getName())) { + return namespace.compareTo(o.getName()); + } + if (!prefix.equalsIgnoreCase(o.getPrefix())) { + return prefix.compareTo(o.getPrefix()); + } return 0; } @@ -70,9 +72,9 @@ public class SimpleMongoDBNamespaceManager implements MongoDBNamespaceManager { public class MongoCursorIteration implements CloseableIteration<Namespace, RyaDAOException> { - private DBCursor cursor; + private final DBCursor cursor; - public MongoCursorIteration(DBCursor cursor2) { + public MongoCursorIteration(final DBCursor cursor2) { this.cursor = cursor2; } @@ -83,12 +85,12 @@ public class SimpleMongoDBNamespaceManager implements MongoDBNamespaceManager { @Override public Namespace next() throws RyaDAOException { - DBObject ns = cursor.next(); - Map values = ns.toMap(); - String namespace = (String) values.get(NAMESPACE); - String prefix = (String) values.get(PREFIX); - - Namespace temp = new NamespaceImplementation(namespace, prefix); + final DBObject ns = cursor.next(); + final Map values = ns.toMap(); + final String namespace = (String) values.get(NAMESPACE); + final String prefix = (String) values.get(PREFIX); + + final Namespace temp = new NamespaceImplementation(namespace, prefix); return temp; } @@ -108,22 +110,22 @@ public class SimpleMongoDBNamespaceManager implements MongoDBNamespaceManager { private static final String PREFIX = "prefix"; private static final String NAMESPACE = "namespace"; private MongoDBRdfConfiguration conf; - private DBCollection nsColl; + private final DBCollection nsColl; - public SimpleMongoDBNamespaceManager(DBCollection nameSpaceCollection) { + public SimpleMongoDBNamespaceManager(final DBCollection nameSpaceCollection) { nsColl = nameSpaceCollection; } - + @Override - public void createIndices(DBCollection coll){ + public void createIndices(final DBCollection coll){ coll.createIndex(PREFIX); coll.createIndex(NAMESPACE); } @Override - public void setConf(MongoDBRdfConfiguration paramC) { + public void setConf(final MongoDBRdfConfiguration paramC) { this.conf = paramC; } @@ -134,47 +136,47 @@ public class SimpleMongoDBNamespaceManager implements MongoDBNamespaceManager { } @Override - public void addNamespace(String prefix, String namespace) + public void addNamespace(final String prefix, final String namespace) throws RyaDAOException { - String id = prefix; - byte[] bytes = id.getBytes(); + final String id = prefix; + byte[] bytes = id.getBytes(StandardCharsets.UTF_8); try { - MessageDigest digest = MessageDigest.getInstance("SHA-1"); + final MessageDigest digest = MessageDigest.getInstance("SHA-1"); bytes = digest.digest(bytes); - } catch (NoSuchAlgorithmException e) { + } catch (final NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } - BasicDBObject doc = new BasicDBObject(ID, new String(Hex.encodeHex(bytes))) + final BasicDBObject doc = new BasicDBObject(ID, new String(Hex.encodeHex(bytes))) .append(PREFIX, prefix) .append(NAMESPACE, namespace); nsColl.insert(doc); - + } @Override - public String getNamespace(String prefix) throws RyaDAOException { - DBObject query = new BasicDBObject().append(PREFIX, prefix); - DBCursor cursor = nsColl.find(query); + public String getNamespace(final String prefix) throws RyaDAOException { + final DBObject query = new BasicDBObject().append(PREFIX, prefix); + final DBCursor cursor = nsColl.find(query); String nameSpace = prefix; while (cursor.hasNext()){ - DBObject obj = cursor.next(); + final DBObject obj = cursor.next(); nameSpace = (String) obj.toMap().get(NAMESPACE); } return nameSpace; } @Override - public void removeNamespace(String prefix) throws RyaDAOException { - DBObject query = new BasicDBObject().append(PREFIX, prefix); + public void removeNamespace(final String prefix) throws RyaDAOException { + final DBObject query = new BasicDBObject().append(PREFIX, prefix); nsColl.remove(query); } @Override public CloseableIteration<? extends Namespace, RyaDAOException> iterateNamespace() throws RyaDAOException { - DBObject query = new BasicDBObject(); - DBCursor cursor = nsColl.find(query); + final DBObject query = new BasicDBObject(); + final DBCursor cursor = nsColl.find(query); return new MongoCursorIteration(cursor); } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/538cfccc/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java index a8f548c..388e807 100644 --- a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java +++ b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java @@ -1,5 +1,3 @@ -package org.apache.rya.mongodb.dao; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,9 +16,11 @@ package org.apache.rya.mongodb.dao; * specific language governing permissions and limitations * under the License. */ +package org.apache.rya.mongodb.dao; import static org.openrdf.model.vocabulary.XMLSchema.ANYURI; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Map; @@ -166,7 +166,7 @@ public class SimpleMongoDBStorageStrategy implements MongoDBStorageStrategy<RyaS } final String id = statement.getSubject().getData() + " " + statement.getPredicate().getData() + " " + statement.getObject().getData() + " " + context; - byte[] bytes = id.getBytes(); + byte[] bytes = id.getBytes(StandardCharsets.UTF_8); try { final MessageDigest digest = MessageDigest.getInstance("SHA-1"); bytes = digest.digest(bytes); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/538cfccc/extras/indexing/src/main/java/org/apache/rya/accumulo/documentIndex/DocumentIndexIntersectingIterator.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/accumulo/documentIndex/DocumentIndexIntersectingIterator.java b/extras/indexing/src/main/java/org/apache/rya/accumulo/documentIndex/DocumentIndexIntersectingIterator.java index 6e5b72f..595fc36 100644 --- a/extras/indexing/src/main/java/org/apache/rya/accumulo/documentIndex/DocumentIndexIntersectingIterator.java +++ b/extras/indexing/src/main/java/org/apache/rya/accumulo/documentIndex/DocumentIndexIntersectingIterator.java @@ -20,6 +20,7 @@ package org.apache.rya.accumulo.documentIndex; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -33,7 +34,6 @@ import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.iterators.IteratorEnvironment; import org.apache.accumulo.core.iterators.SortedKeyValueIterator; -import org.apache.accumulo.core.tabletserver.thrift.TabletClientService; import org.apache.accumulo.core.util.TextUtil; import org.apache.commons.codec.binary.Base64; import org.apache.hadoop.io.Text; @@ -560,9 +560,9 @@ public class DocumentIndexIntersectingIterator implements SortedKeyValueIterator protected static String encodeColumns(TextColumn[] columns) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < columns.length; i++) { - sb.append(new String(Base64.encodeBase64(TextUtil.getBytes(columns[i].getColumnFamily())))); + sb.append(new String(Base64.encodeBase64(TextUtil.getBytes(columns[i].getColumnFamily())), StandardCharsets.UTF_8)); sb.append('\n'); - sb.append(new String(Base64.encodeBase64(TextUtil.getBytes(columns[i].getColumnQualifier())))); + sb.append(new String(Base64.encodeBase64(TextUtil.getBytes(columns[i].getColumnQualifier())), StandardCharsets.UTF_8)); sb.append('\u0001'); } return sb.toString(); @@ -575,8 +575,8 @@ public class DocumentIndexIntersectingIterator implements SortedKeyValueIterator TextColumn[] columnTexts = new TextColumn[columnStrings.length]; for (int i = 0; i < columnStrings.length; i++) { String[] columnComponents = columnStrings[i].split("\n"); - columnTexts[i] = new TextColumn(new Text(Base64.decodeBase64(columnComponents[0].getBytes())), - new Text(Base64.decodeBase64(columnComponents[1].getBytes()))); + columnTexts[i] = new TextColumn(new Text(Base64.decodeBase64(columnComponents[0].getBytes(StandardCharsets.UTF_8))), + new Text(Base64.decodeBase64(columnComponents[1].getBytes(StandardCharsets.UTF_8)))); } return columnTexts; } @@ -591,7 +591,7 @@ public class DocumentIndexIntersectingIterator implements SortedKeyValueIterator */ protected static String encodeContext(String context) { - return new String(Base64.encodeBase64(context.getBytes())); + return new String(Base64.encodeBase64(context.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); } @@ -605,7 +605,7 @@ public class DocumentIndexIntersectingIterator implements SortedKeyValueIterator if (context == null) { return null; } else { - return new String(Base64.decodeBase64(context.getBytes())); + return new String(Base64.decodeBase64(context.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); } } @@ -621,7 +621,7 @@ public class DocumentIndexIntersectingIterator implements SortedKeyValueIterator else bytes[i] = 0; } - return new String(Base64.encodeBase64(bytes)); + return new String(Base64.encodeBase64(bytes), StandardCharsets.UTF_8); } /** @@ -633,7 +633,7 @@ public class DocumentIndexIntersectingIterator implements SortedKeyValueIterator if (prefixes == null) return null; - byte[] bytes = Base64.decodeBase64(prefixes.getBytes()); + byte[] bytes = Base64.decodeBase64(prefixes.getBytes(StandardCharsets.UTF_8)); boolean[] bFlags = new boolean[bytes.length]; for (int i = 0; i < bytes.length; i++) { if (bytes[i] == 1) http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/538cfccc/extras/indexing/src/main/java/org/apache/rya/indexing/KeyParts.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/KeyParts.java b/extras/indexing/src/main/java/org/apache/rya/indexing/KeyParts.java index 1e988fe..11ff8c0 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/KeyParts.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/KeyParts.java @@ -1,5 +1,3 @@ -package org.apache.rya.indexing; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,8 +16,9 @@ package org.apache.rya.indexing; * specific language governing permissions and limitations * under the License. */ +package org.apache.rya.indexing; - +import java.nio.charset.StandardCharsets; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -202,7 +201,7 @@ public class KeyParts implements Iterable<KeyParts> { return "KeyParts [contraintPrefix=" + toHumanString(constraintPrefix) + ", instant=" + toHumanString(instant.getAsKeyBytes()) + ", cf=" + cf + ", cq=" + cq + "]"; } private static void appendSubject(final Statement statement, final Text keyText) { - final Value statementValue = new Value(StatementSerializer.writeSubject(statement).getBytes()); + final Value statementValue = new Value(StatementSerializer.writeSubject(statement).getBytes(StandardCharsets.UTF_8)); final byte[] hashOfValue = uniqueFromValueForKey(statementValue); appendBytes(HASH_PREFIX, keyText); // prefix the hash with a zero byte. appendBytes(hashOfValue, keyText); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/538cfccc/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/AccumuloDocIdIndexer.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/AccumuloDocIdIndexer.java b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/AccumuloDocIdIndexer.java index a84670f..25a272d 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/AccumuloDocIdIndexer.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/AccumuloDocIdIndexer.java @@ -1,5 +1,3 @@ -package org.apache.rya.indexing.accumulo.entity; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,13 +16,13 @@ package org.apache.rya.indexing.accumulo.entity; * specific language governing permissions and limitations * under the License. */ - +package org.apache.rya.indexing.accumulo.entity; import static org.apache.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTE; import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTE; -import info.aduna.iteration.CloseableIteration; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -35,17 +33,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.Set; -import org.apache.rya.accumulo.AccumuloRdfConfiguration; -import org.apache.rya.accumulo.documentIndex.DocIndexIteratorUtil; -import org.apache.rya.accumulo.documentIndex.DocumentIndexIntersectingIterator; -import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.domain.RyaURI; -import org.apache.rya.api.resolver.RyaContext; -import org.apache.rya.api.resolver.RyaToRdfConversions; -import org.apache.rya.api.resolver.RyaTypeResolverException; -import org.apache.rya.indexing.DocIdIndexer; -import org.apache.rya.indexing.accumulo.ConfigUtils; - import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.BatchScanner; @@ -57,6 +44,16 @@ import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.security.Authorizations; import org.apache.hadoop.io.Text; +import org.apache.rya.accumulo.AccumuloRdfConfiguration; +import org.apache.rya.accumulo.documentIndex.DocIndexIteratorUtil; +import org.apache.rya.accumulo.documentIndex.DocumentIndexIntersectingIterator; +import org.apache.rya.api.RdfCloudTripleStoreConfiguration; +import org.apache.rya.api.domain.RyaURI; +import org.apache.rya.api.resolver.RyaContext; +import org.apache.rya.api.resolver.RyaToRdfConversions; +import org.apache.rya.api.resolver.RyaTypeResolverException; +import org.apache.rya.indexing.DocIdIndexer; +import org.apache.rya.indexing.accumulo.ConfigUtils; import org.openrdf.query.BindingSet; import org.openrdf.query.MalformedQueryException; import org.openrdf.query.QueryEvaluationException; @@ -72,14 +69,16 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.Sets; import com.google.common.primitives.Bytes; +import info.aduna.iteration.CloseableIteration; + public class AccumuloDocIdIndexer implements DocIdIndexer { private BatchScanner bs; - private AccumuloRdfConfiguration conf; + private final AccumuloRdfConfiguration conf; - public AccumuloDocIdIndexer(RdfCloudTripleStoreConfiguration conf) throws AccumuloException, AccumuloSecurityException { + public AccumuloDocIdIndexer(final RdfCloudTripleStoreConfiguration conf) throws AccumuloException, AccumuloSecurityException { Preconditions.checkArgument(conf instanceof RdfCloudTripleStoreConfiguration, "conf must be isntance of RdfCloudTripleStoreConfiguration"); this.conf = (AccumuloRdfConfiguration) conf; //Connector conn = ConfigUtils.getConnector(conf); @@ -88,22 +87,22 @@ public class AccumuloDocIdIndexer implements DocIdIndexer { - public CloseableIteration<BindingSet, QueryEvaluationException> queryDocIndex(String sparqlQuery, - Collection<BindingSet> constraints) throws TableNotFoundException, QueryEvaluationException { + public CloseableIteration<BindingSet, QueryEvaluationException> queryDocIndex(final String sparqlQuery, + final Collection<BindingSet> constraints) throws TableNotFoundException, QueryEvaluationException { - SPARQLParser parser = new SPARQLParser(); + final SPARQLParser parser = new SPARQLParser(); ParsedQuery pq1 = null; try { pq1 = parser.parseQuery(sparqlQuery, null); - } catch (MalformedQueryException e) { + } catch (final MalformedQueryException e) { e.printStackTrace(); } - TupleExpr te1 = pq1.getTupleExpr(); - List<StatementPattern> spList1 = StatementPatternCollector.process(te1); + final TupleExpr te1 = pq1.getTupleExpr(); + final List<StatementPattern> spList1 = StatementPatternCollector.process(te1); if(StarQuery.isValidStarQuery(spList1)) { - StarQuery sq1 = new StarQuery(spList1); + final StarQuery sq1 = new StarQuery(spList1); return queryDocIndex(sq1, constraints); } else { throw new IllegalArgumentException("Invalid star query!"); @@ -115,8 +114,8 @@ public class AccumuloDocIdIndexer implements DocIdIndexer { @Override - public CloseableIteration<BindingSet, QueryEvaluationException> queryDocIndex(StarQuery query, - Collection<BindingSet> constraints) throws TableNotFoundException, QueryEvaluationException { + public CloseableIteration<BindingSet, QueryEvaluationException> queryDocIndex(final StarQuery query, + final Collection<BindingSet> constraints) throws TableNotFoundException, QueryEvaluationException { final StarQuery starQ = query; final Iterator<BindingSet> bs = constraints.iterator(); @@ -124,7 +123,7 @@ public class AccumuloDocIdIndexer implements DocIdIndexer { final Set<String> unCommonVarNames; final Set<String> commonVarNames; if (bs2.hasNext()) { - BindingSet currBs = bs2.next(); + final BindingSet currBs = bs2.next(); commonVarNames = StarQuery.getCommonVars(query, currBs); unCommonVarNames = Sets.difference(currBs.getBindingNames(), commonVarNames); } else { @@ -138,17 +137,17 @@ public class AccumuloDocIdIndexer implements DocIdIndexer { final String commonVar = starQ.getCommonVarName(); final Iterator<Entry<Key, Value>> intersections; final BatchScanner scan; - Set<Range> ranges = Sets.newHashSet(); + final Set<Range> ranges = Sets.newHashSet(); while(bs.hasNext()) { - BindingSet currentBs = bs.next(); + final BindingSet currentBs = bs.next(); if(currentBs.getBinding(commonVar) == null) { continue; } - String row = currentBs.getBinding(commonVar).getValue().stringValue(); + final String row = currentBs.getBinding(commonVar).getValue().stringValue(); ranges.add(new Range(row)); map.put(row, currentBs); @@ -246,7 +245,7 @@ public class AccumuloDocIdIndexer implements DocIdIndexer { private boolean init = false; private BindingSet currentBs; private StarQuery sq = new StarQuery(starQ); - private Set<Range> emptyRangeSet = Sets.newHashSet(); + private final Set<Range> emptyRangeSet = Sets.newHashSet(); private BatchScanner scan; @Override @@ -327,16 +326,16 @@ public class AccumuloDocIdIndexer implements DocIdIndexer { } } - private QueryBindingSet deserializeKey(Key key, StarQuery sq, BindingSet currentBs, Set<String> unCommonVar) { + private QueryBindingSet deserializeKey(final Key key, final StarQuery sq, final BindingSet currentBs, final Set<String> unCommonVar) { - QueryBindingSet currentSolutionBs = new QueryBindingSet(); + final QueryBindingSet currentSolutionBs = new QueryBindingSet(); - Text row = key.getRow(); - Text cq = key.getColumnQualifier(); + final Text row = key.getRow(); + final Text cq = key.getColumnQualifier(); - String[] cqArray = cq.toString().split(DocIndexIteratorUtil.DOC_ID_INDEX_DELIM); + final String[] cqArray = cq.toString().split(DocIndexIteratorUtil.DOC_ID_INDEX_DELIM); boolean commonVarSet = false; @@ -346,63 +345,63 @@ public class AccumuloDocIdIndexer implements DocIdIndexer { } if (!commonVarSet && sq.isCommonVarURI()) { - RyaURI rURI = new RyaURI(row.toString()); + final RyaURI rURI = new RyaURI(row.toString()); currentSolutionBs.addBinding(sq.getCommonVarName(), RyaToRdfConversions.convertValue(rURI)); commonVarSet = true; } - for (String s : sq.getUnCommonVars()) { + for (final String s : sq.getUnCommonVars()) { - byte[] cqBytes = cqArray[sq.getVarPos().get(s)].getBytes(); - int firstIndex = Bytes.indexOf(cqBytes, DELIM_BYTE); - int secondIndex = Bytes.lastIndexOf(cqBytes, DELIM_BYTE); - int typeIndex = Bytes.indexOf(cqBytes, TYPE_DELIM_BYTE); - byte[] tripleComponent = Arrays.copyOfRange(cqBytes, firstIndex + 1, secondIndex); - byte[] cqContent = Arrays.copyOfRange(cqBytes, secondIndex + 1, typeIndex); - byte[] objType = Arrays.copyOfRange(cqBytes, typeIndex, cqBytes.length); + final byte[] cqBytes = cqArray[sq.getVarPos().get(s)].getBytes(StandardCharsets.UTF_8); + final int firstIndex = Bytes.indexOf(cqBytes, DELIM_BYTE); + final int secondIndex = Bytes.lastIndexOf(cqBytes, DELIM_BYTE); + final int typeIndex = Bytes.indexOf(cqBytes, TYPE_DELIM_BYTE); + final String tripleComponent = new String(Arrays.copyOfRange(cqBytes, firstIndex + 1, secondIndex), StandardCharsets.UTF_8); + final byte[] cqContent = Arrays.copyOfRange(cqBytes, secondIndex + 1, typeIndex); + final byte[] objType = Arrays.copyOfRange(cqBytes, typeIndex, cqBytes.length); - if (new String(tripleComponent).equals("object")) { - byte[] object = Bytes.concat(cqContent, objType); + if (tripleComponent.equals("object")) { + final byte[] object = Bytes.concat(cqContent, objType); org.openrdf.model.Value v = null; try { v = RyaToRdfConversions.convertValue(RyaContext.getInstance().deserialize( object)); - } catch (RyaTypeResolverException e) { + } catch (final RyaTypeResolverException e) { e.printStackTrace(); } currentSolutionBs.addBinding(s, v); - } else if (new String(tripleComponent).equals("subject")) { + } else if (tripleComponent.equals("subject")) { if (!commonVarSet) { - byte[] object = Bytes.concat(row.getBytes(), objType); + final byte[] object = Bytes.concat(row.getBytes(), objType); org.openrdf.model.Value v = null; try { v = RyaToRdfConversions.convertValue(RyaContext.getInstance().deserialize( object)); - } catch (RyaTypeResolverException e) { + } catch (final RyaTypeResolverException e) { e.printStackTrace(); } currentSolutionBs.addBinding(sq.getCommonVarName(), v); commonVarSet = true; } - RyaURI rURI = new RyaURI(new String(cqContent)); + final RyaURI rURI = new RyaURI(new String(cqContent, StandardCharsets.UTF_8)); currentSolutionBs.addBinding(s, RyaToRdfConversions.convertValue(rURI)); } else { throw new IllegalArgumentException("Invalid row."); } } - for (String s : unCommonVar) { + for (final String s : unCommonVar) { currentSolutionBs.addBinding(s, currentBs.getValue(s)); } return currentSolutionBs; } - private BatchScanner runQuery(StarQuery query, Collection<Range> ranges) throws QueryEvaluationException { + private BatchScanner runQuery(final StarQuery query, Collection<Range> ranges) throws QueryEvaluationException { try { if (ranges.size() == 0) { - String rangeText = query.getCommonVarValue(); + final String rangeText = query.getCommonVarValue(); Range r; if (rangeText != null) { r = new Range(new Text(query.getCommonVarValue())); @@ -412,15 +411,15 @@ public class AccumuloDocIdIndexer implements DocIdIndexer { ranges = Collections.singleton(r); } - Connector accCon = ConfigUtils.getConnector(conf); - IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class); + final Connector accCon = ConfigUtils.getConnector(conf); + final IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class); DocumentIndexIntersectingIterator.setColumnFamilies(is, query.getColumnCond()); if (query.hasContext()) { DocumentIndexIntersectingIterator.setContext(is, query.getContextURI()); } - + final Authorizations auths; final String authsStr = conf.get(ConfigUtils.CLOUDBASE_AUTHS); if(authsStr == null || authsStr.isEmpty()) { @@ -428,7 +427,7 @@ public class AccumuloDocIdIndexer implements DocIdIndexer { } else { auths = new Authorizations(authsStr); } - + bs = accCon.createBatchScanner(EntityCentricIndex.getTableName(conf), auths, 15); bs.addScanIterator(is); bs.setRanges(ranges); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/538cfccc/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/EntityCentricIndex.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/EntityCentricIndex.java b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/EntityCentricIndex.java index 0676e3d..ab4bd55 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/EntityCentricIndex.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/EntityCentricIndex.java @@ -27,6 +27,7 @@ import static org.apache.rya.api.RdfCloudTripleStoreConstants.EMPTY_TEXT; import static org.apache.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -68,6 +69,9 @@ public class EntityCentricIndex extends AbstractAccumuloIndexer { private static final Logger logger = Logger.getLogger(EntityCentricIndex.class); private static final String TABLE_SUFFIX = "EntityCentricIndex"; + private static final String OBJECT = "object"; + private static final String SUBJECT = "subject"; + private AccumuloRdfConfiguration conf; private BatchWriter writer; private boolean isInit = false; @@ -235,15 +239,15 @@ public class EntityCentricIndex extends AbstractAccumuloIndexer { final byte[] columnVisibility = stmt.getColumnVisibility(); final byte[] value = stmt.getValue(); assert subject != null && predicate != null && object != null; - final byte[] cf = (context == null) ? EMPTY_BYTES : context.getData().getBytes(); - final byte[] subjBytes = subject.getData().getBytes(); - final byte[] predBytes = predicate.getData().getBytes(); + final byte[] cf = (context == null) ? EMPTY_BYTES : context.getData().getBytes(StandardCharsets.UTF_8); + final byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8); + final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8); final byte[][] objBytes = RyaContext.getInstance().serializeType(object); return Lists.newArrayList(new TripleRow(subjBytes, predBytes, Bytes.concat(cf, DELIM_BYTES, - "object".getBytes(), DELIM_BYTES, + OBJECT.getBytes(StandardCharsets.UTF_8), DELIM_BYTES, objBytes[0], objBytes[1]), timestamp, columnVisibility, @@ -251,7 +255,7 @@ public class EntityCentricIndex extends AbstractAccumuloIndexer { new TripleRow(objBytes[0], predBytes, Bytes.concat(cf, DELIM_BYTES, - "subject".getBytes(), DELIM_BYTES, + SUBJECT.getBytes(StandardCharsets.UTF_8), DELIM_BYTES, subjBytes, objBytes[1]), timestamp, columnVisibility, @@ -282,25 +286,25 @@ public class EntityCentricIndex extends AbstractAccumuloIndexer { final byte[] columnFamily = Arrays.copyOf(data, split); final byte[] edgeBytes = Arrays.copyOfRange(data, split + DELIM_BYTES.length, data.length); split = Bytes.indexOf(edgeBytes, DELIM_BYTES); - String otherNodeVar = new String(Arrays.copyOf(edgeBytes, split)); - byte[] otherNodeBytes = Arrays.copyOfRange(edgeBytes, split + DELIM_BYTES.length, edgeBytes.length); + final String otherNodeVar = new String(Arrays.copyOf(edgeBytes, split), StandardCharsets.UTF_8); + final byte[] otherNodeBytes = Arrays.copyOfRange(edgeBytes, split + DELIM_BYTES.length, edgeBytes.length); split = Bytes.indexOf(otherNodeBytes, TYPE_DELIM_BYTES); - byte[] otherNodeData = Arrays.copyOf(otherNodeBytes, split); - byte[] typeBytes = Arrays.copyOfRange(otherNodeBytes, split, otherNodeBytes.length); + final byte[] otherNodeData = Arrays.copyOf(otherNodeBytes, split); + final byte[] typeBytes = Arrays.copyOfRange(otherNodeBytes, split, otherNodeBytes.length); byte[] objectBytes; RyaURI subject; - final RyaURI predicate = new RyaURI(new String(predicateBytes)); + final RyaURI predicate = new RyaURI(new String(predicateBytes, StandardCharsets.UTF_8)); RyaType object; RyaURI context = null; // Expect either: entity=subject.data, otherNodeVar="object", otherNodeBytes={object.data, object.datatype} // or: entity=object.data, otherNodeVar="subject", otherNodeBytes={subject.data, object.datatype} switch (otherNodeVar) { - case "subject": - subject = new RyaURI(new String(otherNodeData)); + case SUBJECT: + subject = new RyaURI(new String(otherNodeData, StandardCharsets.UTF_8)); objectBytes = Bytes.concat(entityBytes, typeBytes); break; - case "object": - subject = new RyaURI(new String(entityBytes)); + case OBJECT: + subject = new RyaURI(new String(entityBytes, StandardCharsets.UTF_8)); objectBytes = Bytes.concat(otherNodeData, typeBytes); break; default: @@ -309,7 +313,7 @@ public class EntityCentricIndex extends AbstractAccumuloIndexer { } object = RyaContext.getInstance().deserialize(objectBytes); if (columnFamily != null && columnFamily.length > 0) { - context = new RyaURI(new String(columnFamily)); + context = new RyaURI(new String(columnFamily, StandardCharsets.UTF_8)); } return new RyaStatement(subject, predicate, object, context, null, columnVisibility, valueBytes, timestamp); @@ -323,33 +327,33 @@ public class EntityCentricIndex extends AbstractAccumuloIndexer { * @throws IOException if edge direction can't be extracted as expected. * @throws RyaTypeResolverException if a type error occurs deserializing the statement's object. */ - public static RyaType getRyaType(Key key, Value value) throws RyaTypeResolverException, IOException { + public static RyaType getRyaType(final Key key, final Value value) throws RyaTypeResolverException, IOException { assert key != null; assert value != null; - byte[] entityBytes = key.getRowData().toArray(); - byte[] data = key.getColumnQualifierData().toArray(); + final byte[] entityBytes = key.getRowData().toArray(); + final byte[] data = key.getColumnQualifierData().toArray(); // main entity is either the subject or object // data contains: column family , var name of other node , data of other node + datatype of object int split = Bytes.indexOf(data, DELIM_BYTES); - byte[] edgeBytes = Arrays.copyOfRange(data, split + DELIM_BYTES.length, data.length); + final byte[] edgeBytes = Arrays.copyOfRange(data, split + DELIM_BYTES.length, data.length); split = Bytes.indexOf(edgeBytes, DELIM_BYTES); - String otherNodeVar = new String(Arrays.copyOf(edgeBytes, split)); - byte[] otherNodeBytes = Arrays.copyOfRange(edgeBytes, split + DELIM_BYTES.length, edgeBytes.length); + final String otherNodeVar = new String(Arrays.copyOf(edgeBytes, split), StandardCharsets.UTF_8); + final byte[] otherNodeBytes = Arrays.copyOfRange(edgeBytes, split + DELIM_BYTES.length, edgeBytes.length); split = Bytes.indexOf(otherNodeBytes, TYPE_DELIM_BYTES); - byte[] typeBytes = Arrays.copyOfRange(otherNodeBytes, split, otherNodeBytes.length); + final byte[] typeBytes = Arrays.copyOfRange(otherNodeBytes, split, otherNodeBytes.length); byte[] objectBytes; RyaURI subject; RyaType object; RyaType type = null; switch (otherNodeVar) { - case "subject": + case SUBJECT: objectBytes = Bytes.concat(entityBytes, typeBytes); - object = RyaContext.getInstance().deserialize(objectBytes); //return this + object = RyaContext.getInstance().deserialize(objectBytes); type = object; break; - case "object": - subject = new RyaURI(new String(entityBytes));//return this + case OBJECT: + subject = new RyaURI(new String(entityBytes, StandardCharsets.UTF_8)); type = subject; break; default: