List of usage examples for com.google.common.io ByteArrayDataInput readLong
@Override
long readLong();
From source file:com.facebook.presto.raptor.RaptorColumnIdentity.java
public static RaptorColumnIdentity deserialize(byte[] bytes) { checkArgument(bytes.length >= Byte.BYTES, "bytes for RaptorColumnIdentity is corrupt"); ByteArrayDataInput input = newDataInput(bytes); byte version = input.readByte(); if ((version == CURRENT_VERSION) && (bytes.length == SERIALIZED_SIZE)) { long columnId = input.readLong(); return new RaptorColumnIdentity(columnId); }// w w w . ja va 2s .c om throw new PrestoException(CORRUPT_SERIALIZED_IDENTITY, "RaptorColumnIdentity is corrupt: " + base16().lowerCase().encode(bytes)); }
From source file:com.facebook.presto.raptor.RaptorTableIdentity.java
public static RaptorTableIdentity deserialize(byte[] bytes) { checkArgument(bytes.length >= Byte.BYTES, "bytes for RaptorTableIdentity is corrupt"); ByteArrayDataInput input = newDataInput(bytes); byte version = input.readByte(); if ((version == CURRENT_VERSION) && (bytes.length == SERIALIZED_SIZE)) { long tableId = input.readLong(); return new RaptorTableIdentity(tableId); }/*from w w w . ja v a2 s. c o m*/ throw new PrestoException(CORRUPT_SERIALIZED_IDENTITY, "RaptorTableIdentity is corrupt: " + base16().lowerCase().encode(bytes)); }
From source file:com.volumetricpixels.rockyplugin.chunk.ChunkCacheHandler.java
/** * Handle packet that the player send us for nearby hashes * //w w w .ja v a 2s. c o m * @param player * the name of the packet * @param packet * the packet to handle */ public static void handlePacket(String player, Packet250CustomPayload packet) { Set<Long> playerCache = cache.getPlayerCache(player); ByteArrayDataInput in = ByteStreams.newDataInput(packet.data); int hashLength = in.readShort(); for (int i = 0; i < hashLength; i++) { playerCache.add(in.readLong()); } }
From source file:de.nx42.maps4cim.header.HeaderParser.java
/** * Actually parses the relevant part of the header and writes the results * into a new CustomHeader-object/*from ww w .ja va 2 s . co m*/ * @param header a byte-array containing at least the relevant part of the * map's header (can be retrieved via {@link HeaderParser#getRelevantPart(InputStream)}) * @return the CustomHeader-object containing the data of this header * @throws ParseException if there is an error parsing the header */ protected static CustomHeader execute(byte[] header) throws ParseException { CustomHeader ch = CustomHeader.newEmpty(); // read intro int introEnd = readToString(header, 0); ch.intro = Arrays.copyOfRange(header, 0, introEnd); // read date/times int dateStart = readAfterGap(header, introEnd, 3); int dateEnd = readAfterBytes(header, dateStart, CustomHeader.staticBinary01) - CustomHeader.staticBinary01.length; // read 64 bit integers (date/time) until end is reached int dateAmount = (dateEnd - dateStart) / 8; long[] dateTimeStamps = new long[dateAmount]; ByteArrayDataInput bin = ByteStreams.newDataInput(header, dateStart); for (int i = 0; i < dateAmount; i++) { dateTimeStamps[i] = bin.readLong(); } // interpret dates if (dateAmount >= 6) { // current format (custom map) ch.unusedDate1 = DateUtils.ticksToDate(dateTimeStamps[0]); ch.unusedDate2 = DateUtils.ticksToDate(dateTimeStamps[1]); ch.lastSaved = DateUtils.ticksToDate(dateTimeStamps[2]); ch.mapCreated = DateUtils.ticksToDate(dateTimeStamps[3]); ch.workTime1 = dateTimeStamps[4]; ch.workTime2 = dateTimeStamps[5]; } else if (dateAmount >= 4) { // old format (campaign map), without mapCreated and workTime2 ch.unusedDate1 = DateUtils.ticksToDate(dateTimeStamps[0]); ch.unusedDate2 = DateUtils.ticksToDate(dateTimeStamps[1]); ch.lastSaved = ch.mapCreated = DateUtils.ticksToDate(dateTimeStamps[2]); ch.workTime1 = ch.workTime2 = dateTimeStamps[3]; } else { // fail, just write some default values log.warn("Can't read date & time values: unexpected format"); ch.unusedDate1 = ch.unusedDate2 = CustomHeader.unusedDateDefault; ch.lastSaved = ch.mapCreated = DateUtils.getDateUTC(2013, 1, 1, 12, 0, 0); } // read map name int nameStart = readAfterString(header, dateEnd, CustomHeader.staticString02); ch.mapName = parseHeaderString(header, nameStart); // get minimap PNG length (watch out for euro update strings!) int mapNameEnd = readAfterString(header, nameStart); int beginPngLen = mapNameEnd; int firstStringAfterMapName = readToString(header, mapNameEnd); if (mapNameEnd == firstStringAfterMapName) { beginPngLen = readAfterString(header, firstStringAfterMapName); } // read minimap image ch.pngLength = Arrays.copyOfRange(header, beginPngLen, beginPngLen + 3); int beginPng = beginPngLen + 3; int pngLength = int24parse(ch.pngLength); int pngEnd = beginPng + pngLength; ch.png = Arrays.copyOfRange(header, beginPng, pngEnd); // find out if euro building style int firstStringAfterPng = readToString(header, pngEnd); String europeIdentifier = parseHeaderString(header, firstStringAfterPng); ch.buildingSet = europeIdentifier.contains("cim2.europe") ? BuildingSet.EUROPEAN : BuildingSet.AMERICAN; return ch; }
From source file:org.apache.druid.indexer.InputRowSerde.java
public static final InputRow fromBytes(final Map<String, IndexSerdeTypeHelper> typeHelperMap, byte[] data, AggregatorFactory[] aggs) {//from www. ja v a2 s . c o m try { ByteArrayDataInput in = ByteStreams.newDataInput(data); //Read timestamp long timestamp = in.readLong(); Map<String, Object> event = Maps.newHashMap(); //Read dimensions List<String> dimensions = Lists.newArrayList(); int dimNum = WritableUtils.readVInt(in); for (int i = 0; i < dimNum; i++) { String dimension = readString(in); dimensions.add(dimension); IndexSerdeTypeHelper typeHelper = typeHelperMap.get(dimension); if (typeHelper == null) { typeHelper = STRING_HELPER; } Object dimValues = typeHelper.deserialize(in); if (dimValues == null) { continue; } if (typeHelper.getType() == ValueType.STRING) { List<String> dimensionValues = (List<String>) dimValues; if (dimensionValues.size() == 1) { event.put(dimension, dimensionValues.get(0)); } else { event.put(dimension, dimensionValues); } } else { event.put(dimension, dimValues); } } //Read metrics int metricSize = WritableUtils.readVInt(in); for (int i = 0; i < metricSize; i++) { String metric = readString(in); String type = getType(metric, aggs, i); byte metricNullability = in.readByte(); if (metricNullability == NullHandling.IS_NULL_BYTE) { // metric value is null. continue; } if ("float".equals(type)) { event.put(metric, in.readFloat()); } else if ("long".equals(type)) { event.put(metric, WritableUtils.readVLong(in)); } else if ("double".equals(type)) { event.put(metric, in.readDouble()); } else { ComplexMetricSerde serde = getComplexMetricSerde(type); byte[] value = readBytes(in); event.put(metric, serde.fromBytes(value, 0, value.length)); } } return new MapBasedInputRow(timestamp, dimensions, event); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:cherry.foundation.crypto.SecureLongEncoder.java
@Override protected Long bytesToType(byte[] p) { ByteArrayDataInput in = ByteStreams.newDataInput(p); return in.readLong(); }
From source file:org.yogpstop.qp.TileMiningCore.java
@Override public void S_recievePacket(byte pattern, ByteArrayDataInput data, EntityPlayer ep) { switch (pattern) { case CtS_ADD_FORTUNE: this.fortuneList.add(data.readLong()); sendOpenGUI(ep, StC_OPENGUI_FORTUNE); break;/*from w w w . ja v a2 s . c o m*/ case CtS_REMOVE_FORTUNE: this.fortuneList.remove(data.readLong()); sendOpenGUI(ep, StC_OPENGUI_FORTUNE); break; case CtS_ADD_SILKTOUCH: this.silktouchList.add(data.readLong()); sendOpenGUI(ep, StC_OPENGUI_SILKTOUCH); break; case CtS_REMOVE_SILKTOUCH: this.silktouchList.remove(data.readLong()); sendOpenGUI(ep, StC_OPENGUI_SILKTOUCH); break; case CtS_TOGGLE_FORTUNE: this.fortuneInclude = !this.fortuneInclude; sendOpenGUI(ep, StC_OPENGUI_FORTUNE); break; case CtS_TOGGLE_SILKTOUCH: this.silktouchInclude = !this.silktouchInclude; sendOpenGUI(ep, StC_OPENGUI_SILKTOUCH); break; } }
From source file:org.yogpstop.qp.TileBasic.java
@Override protected void S_recievePacket(byte pattern, ByteArrayDataInput data, EntityPlayer ep) { switch (pattern) { case CtS_ADD_FORTUNE: this.fortuneList.add(data.readLong()); sendOpenGUI(ep, StC_OPENGUI_FORTUNE); break;//from w w w . j ava 2s. co m case CtS_REMOVE_FORTUNE: this.fortuneList.remove(data.readLong()); sendOpenGUI(ep, StC_OPENGUI_FORTUNE); break; case CtS_ADD_SILKTOUCH: this.silktouchList.add(data.readLong()); sendOpenGUI(ep, StC_OPENGUI_SILKTOUCH); break; case CtS_REMOVE_SILKTOUCH: this.silktouchList.remove(data.readLong()); sendOpenGUI(ep, StC_OPENGUI_SILKTOUCH); break; case CtS_TOGGLE_FORTUNE: this.fortuneInclude = !this.fortuneInclude; sendOpenGUI(ep, StC_OPENGUI_FORTUNE); break; case CtS_TOGGLE_SILKTOUCH: this.silktouchInclude = !this.silktouchInclude; sendOpenGUI(ep, StC_OPENGUI_SILKTOUCH); break; } }
From source file:org.yogpstop.qp.TileMiningCore.java
@Override public void C_recievePacket(byte pattern, ByteArrayDataInput data, EntityPlayer ep) { switch (pattern) { case StC_OPENGUI_FORTUNE: this.fortuneInclude = data.readBoolean(); this.fortuneList.clear(); int fsize = data.readInt(); for (int i = 0; i < fsize; i++) { this.fortuneList.add(data.readLong()); }/*from w w w . j av a2 s .co m*/ ep.openGui(QuarryPlus.instance, QuarryPlus.guiIdFList, this.worldObj, this.xCoord, this.yCoord, this.zCoord); break; case StC_OPENGUI_SILKTOUCH: this.silktouchInclude = data.readBoolean(); this.silktouchList.clear(); int ssize = data.readInt(); for (int i = 0; i < ssize; i++) { this.silktouchList.add(data.readLong()); } ep.openGui(QuarryPlus.instance, QuarryPlus.guiIdSList, this.worldObj, this.xCoord, this.yCoord, this.zCoord); break; } }
From source file:org.yogpstop.qp.TileBasic.java
@Override protected void C_recievePacket(byte pattern, ByteArrayDataInput data, EntityPlayer ep) { switch (pattern) { case StC_OPENGUI_FORTUNE: this.fortuneInclude = data.readBoolean(); this.fortuneList.clear(); int fsize = data.readInt(); for (int i = 0; i < fsize; i++) { this.fortuneList.add(data.readLong()); }/*from ww w .j a v a 2 s . co m*/ ep.openGui(QuarryPlus.instance, QuarryPlus.guiIdFList, this.worldObj, this.xCoord, this.yCoord, this.zCoord); break; case StC_OPENGUI_SILKTOUCH: this.silktouchInclude = data.readBoolean(); this.silktouchList.clear(); int ssize = data.readInt(); for (int i = 0; i < ssize; i++) { this.silktouchList.add(data.readLong()); } ep.openGui(QuarryPlus.instance, QuarryPlus.guiIdSList, this.worldObj, this.xCoord, this.yCoord, this.zCoord); break; } }