List of usage examples for com.google.common.primitives Bytes concat
public static byte[] concat(byte[]... arrays)
From source file:com.github.zhongl.util.FileAsserter.java
public void contentIs(byte[]... bytesArray) throws IOException { byte[] expect = Bytes.concat(bytesArray); byte[] actual = Arrays.copyOf(Files.toByteArray(file), expect.length); assertThat(actual, is(expect));//from w w w. j a v a 2 s . c o m }
From source file:cpw.mods.fml.common.network.ModIdMapPacket.java
@Override public void execute(INetworkManager network, FMLNetworkHandler handler, NetHandler netHandler, String userName) {/* w w w .ja v a 2s . c o m*/ byte[] allData = Bytes.concat(partials); GameData.initializeServerGate(1); try { NBTTagCompound serverList = CompressedStreamTools.func_74792_a(allData); NBTTagList list = serverList.func_74761_m("List"); Set<ItemData> itemData = GameData.buildWorldItemData(list); GameData.validateWorldSave(itemData); MapDifference<Integer, ItemData> serverDifference = GameData.gateWorldLoadingForValidation(); if (serverDifference != null) { FMLCommonHandler.instance().disconnectIDMismatch(serverDifference, netHandler, network); } } catch (IOException e) { } }
From source file:com.palantir.atlasdb.jackson.AtlasDeserializers.java
private static byte[] deserializeRowish(NameMetadataDescription description, JsonNode node, boolean mustBeFull) { if (node == null) { return new byte[0]; }/* w w w.j av a 2s . co m*/ int size = node.size(); List<NameComponentDescription> components = description.getRowParts(); Preconditions.checkArgument(size <= components.size(), "Received %s values for a row with only %s components.", size, components.size()); Preconditions.checkArgument(!mustBeFull || size == components.size(), "Received %s values for a row with %s components.", size, components.size()); byte[][] bytes = new byte[size][]; for (int i = 0; i < size; i++) { JsonNode value = node.get(i); NameComponentDescription component = components.get(i); bytes[i] = component.getType().convertFromJson(value.toString()); if (component.isReverseOrder()) { EncodingUtils.flipAllBitsInPlace(bytes[i]); } } return Bytes.concat(bytes); }
From source file:org.obm.push.minig.imap.impl.IMAPResponseParser.java
public IMAPResponse parse(MinaIMAPMessage msg) { String response = msg.getMessageLine(); IMAPResponse r = new IMAPResponse(); int idx = response.indexOf(' '); if (idx == -1 && response.length() == 1) { idx = 1;/*from ww w. ja va 2 s. c o m*/ } if (idx < 0) { logger.warn("response without space (forcing bad status): " + response); r.setStatus("BAD"); r.setPayload(response); return r; } String tag = response.substring(0, idx); r.setTag(tag); int statusIdx = response.indexOf(' ', idx + 1); if (statusIdx < 0) { statusIdx = response.length(); } if (idx + 1 < statusIdx) { String status = response.substring(idx + 1, statusIdx); if (logger.isDebugEnabled()) { logger.debug("TAG: " + tag + " STATUS: " + status); } r.setStatus(status); } boolean clientDataExpected = false; if ("+".equals(tag) || !"*".equals(tag)) { clientDataExpected = true; } if (!serverHelloReceived) { clientDataExpected = true; serverHelloReceived = true; } r.setClientDataExpected(clientDataExpected); r.setPayload(response); if (msg.hasFragments()) { byte[] rawData = Bytes.concat(msg.getFragments().toArray(new byte[0][])); r.setStreamData(new ByteArrayInputStream(rawData)); } return r; }
From source file:org.apache.aurora.scheduler.storage.log.StreamManagerImpl.java
@Nullable private LogEntry tryDecodeFrame(Frame frame, Iterator<Log.Entry> entries) throws CodingException { if (!isHeader(frame)) { LOG.warn("Found a frame with no preceding header, skipping."); return null; }// ww w . ja v a 2 s . c o m FrameHeader header = frame.getHeader(); byte[][] chunks = new byte[header.getChunkCount()][]; Hasher hasher = hashFunction.newHasher(); for (int i = 0; i < header.getChunkCount(); i++) { if (!entries.hasNext()) { logBadFrame(header, i); return null; } LogEntry logEntry = decodeLogEntry(entries.next()); if (!isFrame(logEntry)) { logBadFrame(header, i); return logEntry; } Frame chunkFrame = logEntry.getFrame(); if (!isChunk(chunkFrame)) { logBadFrame(header, i); return logEntry; } byte[] chunkData = chunkFrame.getChunk().getData(); hasher.putBytes(chunkData); chunks[i] = chunkData; } if (!Arrays.equals(header.getChecksum(), hasher.hash().asBytes())) { throw new CodingException("Read back a framed log entry that failed its checksum"); } return Entries.thriftBinaryDecode(Bytes.concat(chunks)); }
From source file:org.apache.james.blob.cassandra.CassandraBlobsDAO.java
@Override public CompletableFuture<byte[]> readBytes(BlobId blobId) { try {/*from w w w. java 2 s. c om*/ return readBlobParts(blobId).collectList().map(parts -> Bytes.concat(parts.toArray(new byte[0][]))) .toFuture(); } catch (ObjectStoreException e) { CompletableFuture<byte[]> error = new CompletableFuture<>(); error.completeExceptionally(e); return error; } }