List of usage examples for com.google.common.primitives Bytes lastIndexOf
public static int lastIndexOf(byte[] array, byte target)
From source file:mvm.rya.api.resolver.triple.impl.WholeRowTripleResolver.java
@Override public RyaStatement deserialize(TABLE_LAYOUT table_layout, TripleRow tripleRow) throws TripleRowResolverException { try {/*from w ww .ja v a 2 s. c o m*/ 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(); switch (table_layout) { case SPO: { byte[] obj = Bytes.concat(third, type); return new RyaStatement(new RyaURI(new String(first)), new RyaURI(new String(second)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp); } case PO: { byte[] obj = Bytes.concat(second, type); return new RyaStatement(new RyaURI(new String(third)), new RyaURI(new String(first)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp); } case OSP: { byte[] obj = Bytes.concat(first, type); return new RyaStatement(new RyaURI(new String(second)), new RyaURI(new String(third)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp); } } } catch (RyaTypeResolverException e) { throw new TripleRowResolverException(e); } throw new TripleRowResolverException( "TripleRow[" + tripleRow + "] with Table layout[" + table_layout + "] is not deserializable"); }
From source file:org.apache.rya.api.resolver.triple.impl.WholeRowTripleResolver.java
@Override public RyaStatement deserialize(final TABLE_LAYOUT table_layout, final TripleRow tripleRow) throws TripleRowResolverException { try {//from w w w. j av a2 s . com assert tripleRow != null && table_layout != null; 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: { final byte[] obj = Bytes.concat(third, type); return new RyaStatement(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: { final byte[] obj = Bytes.concat(second, type); return new RyaStatement(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: { final byte[] obj = Bytes.concat(first, type); return new RyaStatement(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 (final RyaTypeResolverException e) { throw new TripleRowResolverException(e); } throw new TripleRowResolverException( "TripleRow[" + tripleRow + "] with Table layout[" + table_layout + "] is not deserializable"); }
From source file:mvm.rya.api.resolver.triple.impl.WholeRowHashedTripleResolver.java
@Override public RyaStatement deserialize(TABLE_LAYOUT table_layout, TripleRow tripleRow) throws TripleRowResolverException { try {//w ww . j a v a 2 s. c o m 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); 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(); switch (table_layout) { case SPO: { byte[] obj = Bytes.concat(third, type); return new RyaStatement(new RyaURI(new String(first)), new RyaURI(new String(second)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp); } case PO: { byte[] obj = Bytes.concat(second, type); return new RyaStatement(new RyaURI(new String(third)), new RyaURI(new String(first)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp); } case OSP: { byte[] obj = Bytes.concat(first, type); return new RyaStatement(new RyaURI(new String(second)), new RyaURI(new String(third)), RyaContext.getInstance().deserialize(obj), context, qualifier, columnVisibility, value, timestamp); } } } catch (RyaTypeResolverException e) { throw new TripleRowResolverException(e); } throw new TripleRowResolverException( "TripleRow[" + tripleRow + "] with Table layout[" + table_layout + "] is not deserializable"); }
From source file:org.apache.rya.api.resolver.triple.impl.WholeRowHashedTripleResolver.java
@Override public RyaStatement deserialize(final TABLE_LAYOUT table_layout, final TripleRow tripleRow) throws TripleRowResolverException { try {// w ww .ja v a 2 s . com 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)) { final int hashStart = Bytes.indexOf(row, DELIM_BYTE); row = Arrays.copyOfRange(row, hashStart + 1, row.length); } 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: { final byte[] obj = Bytes.concat(third, type); return new RyaStatement(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: { final byte[] obj = Bytes.concat(second, type); return new RyaStatement(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: { final byte[] obj = Bytes.concat(first, type); return new RyaStatement(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 (final RyaTypeResolverException e) { throw new TripleRowResolverException(e); } throw new TripleRowResolverException( "TripleRow[" + tripleRow + "] with Table layout[" + table_layout + "] is not deserializable"); }
From source file:org.b1.pack.standard.reader.VolumeCursor.java
private HeaderSet readTail() throws IOException { long available = Preconditions.checkNotNull(volume.getSize(), "Volume size unknown") - inputStream.getCount();/*ww w. j ava 2 s. c o m*/ int capacity = Ints.checkedCast(Math.min(available, MAX_TAIL_SIZE)); ByteStreams.skipFully(inputStream, available - capacity); MemoryOutputStream outputStream = new MemoryOutputStream(capacity); ByteStreams.copy(inputStream, outputStream); Preconditions.checkState(outputStream.size() == capacity); int index = Bytes.lastIndexOf(outputStream.getBuf(), Volumes.SEPARATOR_BYTE) + 1; checkVolume(index > 0); String result = new String(outputStream.getBuf(), index, capacity - index, Charsets.UTF_8.name()); checkVolumeEnd(result); HeaderSet headerSet = new HeaderSet(result); if (packCipher == null) { return headerSet; } byte[] encryptedHeaders = headerSet.getEncryptedHeaders(); checkVolume(encryptedHeaders != null); String plaintext = new String(volumeCipher.cipherTail(false, encryptedHeaders), Charsets.UTF_8.name()); checkVolumeEnd(plaintext); return new HeaderSet(plaintext); }
From source file:com.google.devtools.build.lib.runtime.ExperimentalEventHandler.java
@Override public synchronized void handle(Event event) { try {/* w ww. j a va2 s . c o m*/ if (debugAllEvents) { // Debugging only: show all events visible to the new UI. clearProgressBar(); terminal.flush(); outErr.getOutputStream().write((event + "\n").getBytes(StandardCharsets.UTF_8)); outErr.getOutputStream().flush(); addProgressBar(); terminal.flush(); } else { switch (event.getKind()) { case STDOUT: case STDERR: OutputStream stream = event.getKind() == EventKind.STDOUT ? outErr.getOutputStream() : outErr.getErrorStream(); if (buildComplete) { stream.write(event.getMessageBytes()); stream.flush(); } else { byte[] message = event.getMessageBytes(); int eolIndex = Bytes.lastIndexOf(message, (byte) '\n'); if (eolIndex >= 0) { clearProgressBar(); terminal.flush(); stream.write(event.getKind() == EventKind.STDOUT ? stdoutBuffer : stderrBuffer); stream.write(Arrays.copyOf(message, eolIndex + 1)); byte[] restMessage = Arrays.copyOfRange(message, eolIndex + 1, message.length); if (event.getKind() == EventKind.STDOUT) { stdoutBuffer = restMessage; } else { stderrBuffer = restMessage; } stream.flush(); if (showProgress && cursorControl) { addProgressBar(); } terminal.flush(); } else { if (event.getKind() == EventKind.STDOUT) { stdoutBuffer = Bytes.concat(stdoutBuffer, message); } else { stderrBuffer = Bytes.concat(stderrBuffer, message); } } } break; case ERROR: case FAIL: case WARNING: case INFO: case SUBCOMMAND: boolean incompleteLine; if (showProgress && !buildComplete) { clearProgressBar(); } incompleteLine = flushStdOutStdErrBuffers(); if (incompleteLine) { crlf(); } setEventKindColor(event.getKind()); terminal.writeString(event.getKind() + ": "); terminal.resetTerminal(); incompleteLine = true; if (showTimestamp) { terminal.writeString(TIMESTAMP_FORMAT.print(clock.currentTimeMillis())); } if (event.getLocation() != null) { terminal.writeString(event.getLocation() + ": "); } if (event.getMessage() != null) { terminal.writeString(event.getMessage()); incompleteLine = !event.getMessage().endsWith("\n"); } if (incompleteLine) { crlf(); } if (showProgress && !buildComplete && cursorControl) { addProgressBar(); } terminal.flush(); break; case PROGRESS: if (stateTracker.progressBarTimeDependent()) { refresh(); } break; case START: case FINISH: case PASS: case TIMEOUT: case DEPCHECKER: break; } } } catch (IOException e) { LOG.warning("IO Error writing to output stream: " + e); } }
From source file:mvm.rya.indexing.accumulo.entity.AccumuloDocIdIndexer.java
private QueryBindingSet deserializeKey(Key key, StarQuery sq, BindingSet currentBs, Set<String> unCommonVar) { QueryBindingSet currentSolutionBs = new QueryBindingSet(); Text row = key.getRow();//from w w w .j av a 2 s .co m Text cq = key.getColumnQualifier(); String[] cqArray = cq.toString().split(DocIndexIteratorUtil.DOC_ID_INDEX_DELIM); boolean commonVarSet = false; //if common Var is constant there is no common variable to assign a value to if (sq.commonVarConstant()) { commonVarSet = true; } if (!commonVarSet && sq.isCommonVarURI()) { RyaURI rURI = new RyaURI(row.toString()); currentSolutionBs.addBinding(sq.getCommonVarName(), RyaToRdfConversions.convertValue(rURI)); commonVarSet = true; } for (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); if ((new String(tripleComponent)).equals("object")) { byte[] object = Bytes.concat(cqContent, objType); org.openrdf.model.Value v = null; try { v = RyaToRdfConversions.convertValue(RyaContext.getInstance().deserialize(object)); } catch (RyaTypeResolverException e) { e.printStackTrace(); } currentSolutionBs.addBinding(s, v); } else if ((new String(tripleComponent)).equals("subject")) { if (!commonVarSet) { byte[] object = Bytes.concat(row.getBytes(), objType); org.openrdf.model.Value v = null; try { v = RyaToRdfConversions.convertValue(RyaContext.getInstance().deserialize(object)); } catch (RyaTypeResolverException e) { e.printStackTrace(); } currentSolutionBs.addBinding(sq.getCommonVarName(), v); commonVarSet = true; } RyaURI rURI = new RyaURI(new String(cqContent)); currentSolutionBs.addBinding(s, RyaToRdfConversions.convertValue(rURI)); } else { throw new IllegalArgumentException("Invalid row."); } } for (String s : unCommonVar) { currentSolutionBs.addBinding(s, currentBs.getValue(s)); } return currentSolutionBs; }
From source file:org.apache.rya.indexing.accumulo.entity.AccumuloDocIdIndexer.java
private QueryBindingSet deserializeKey(final Key key, final StarQuery sq, final BindingSet currentBs, final Set<String> unCommonVar) { final QueryBindingSet currentSolutionBs = new QueryBindingSet(); final Text row = key.getRow(); final Text cq = key.getColumnQualifier(); final String[] cqArray = cq.toString().split(DocIndexIteratorUtil.DOC_ID_INDEX_DELIM); boolean commonVarSet = false; //if common Var is constant there is no common variable to assign a value to if (sq.commonVarConstant()) { commonVarSet = true;//from w w w .j av a 2 s . c o m } if (!commonVarSet && sq.isCommonVarURI()) { final RyaURI rURI = new RyaURI(row.toString()); currentSolutionBs.addBinding(sq.getCommonVarName(), RyaToRdfConversions.convertValue(rURI)); commonVarSet = true; } for (final String s : sq.getUnCommonVars()) { 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 (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 (final RyaTypeResolverException e) { e.printStackTrace(); } currentSolutionBs.addBinding(s, v); } else if (tripleComponent.equals("subject")) { if (!commonVarSet) { final byte[] object = Bytes.concat(row.getBytes(), objType); org.openrdf.model.Value v = null; try { v = RyaToRdfConversions.convertValue(RyaContext.getInstance().deserialize(object)); } catch (final RyaTypeResolverException e) { e.printStackTrace(); } currentSolutionBs.addBinding(sq.getCommonVarName(), v); commonVarSet = true; } final RyaURI rURI = new RyaURI(new String(cqContent, StandardCharsets.UTF_8)); currentSolutionBs.addBinding(s, RyaToRdfConversions.convertValue(rURI)); } else { throw new IllegalArgumentException("Invalid row."); } } for (final String s : unCommonVar) { currentSolutionBs.addBinding(s, currentBs.getValue(s)); } return currentSolutionBs; }