/** * Write the actual data contents of the tag, implemented in NBT extension classes */ void write(DataOutput output) throws IOException { if (!this.tagList.isEmpty()) { this.tagType = ((NBTBase)this.tagList.get(0)).getId(); } else { this.tagType = 0; } output.writeByte(this.tagType); output.writeInt(this.tagList.size()); for (int i = 0; i < this.tagList.size(); ++i) { ((NBTBase)this.tagList.get(i)).write(output); } }
/** * FileSystemGroup ::= #scheme (scheme #counter (key value)*)* */ @Override public void write(DataOutput out) throws IOException { WritableUtils.writeVInt(out, map.size()); // #scheme for (Map.Entry<String, Object[]> entry : map.entrySet()) { WritableUtils.writeString(out, entry.getKey()); // scheme // #counter for the above scheme WritableUtils.writeVInt(out, numSetCounters(entry.getValue())); for (Object counter : entry.getValue()) { if (counter == null) continue; @SuppressWarnings("unchecked") FSCounter c = (FSCounter) ((Counter)counter).getUnderlyingCounter(); WritableUtils.writeVInt(out, c.key.ordinal()); // key WritableUtils.writeVLong(out, c.getValue()); // value } } }
@Override public void write(DataOutput out) throws IOException { super.write(out); WritableUtils.writeVInt(out, id); WritableUtils.writeVInt(out, maps); WritableUtils.writeVLong(out, inputRecords); WritableUtils.writeVLong(out, outputBytes); WritableUtils.writeVLong(out, outputRecords); WritableUtils.writeVLong(out, maxMemory); WritableUtils.writeVInt(out, reduces); for (int i = 0; i < reduces; ++i) { out.writeDouble(reduceBytes[i]); out.writeDouble(reduceRecords[i]); } WritableUtils.writeVInt(out, nSpec); for (int i = 0; i < nSpec; ++i) { WritableUtils.writeVLong(out, reduceOutputBytes[i]); WritableUtils.writeVLong(out, reduceOutputRecords[i]); } }
private static void produceRelativePath(String path, Object out) throws IOException { if (path.isEmpty()) { if (out instanceof DataOutput) { DataOutput dos = (DataOutput)out; dos.writeUTF(path); } return; } if (testWritePath(path, System.getProperty("netbeans.user"), "user", out)) { // NOI18N return; } int cnt = 0; for (String p : Clusters.dirs()) { if (testWritePath(path, p, "" + cnt, out)) { return; } cnt++; } if (testWritePath(path, System.getProperty("netbeans.home"), "home", out)) { // NOI18N return; } LOG.log(Level.FINE, "Cannot find relative path for {0}", path); // NOI18N doWritePath("abs", path, out); // NOI18N }
/** * Writes an array of <code>String</code>s to a <code>DataOutput</code>. This method will * serialize a <code>null</code> array and not throw a <code>NullPointerException</code>. * * @throws IOException A problem occurs while writing to <code>out</code> * * @see #readStringArray * @see #writeString */ public static void writeStringArray(String[] array, DataOutput out) throws IOException { InternalDataSerializer.checkOut(out); int length; if (array == null) { length = -1; } else { length = array.length; } InternalDataSerializer.writeArrayLength(length, out); if (logger.isTraceEnabled(LogMarker.SERIALIZER)) { logger.trace(LogMarker.SERIALIZER, "Writing String array of length {}", length); } if (length > 0) { for (int i = 0; i < length; i++) { writeString(array[i], out); } } }
private int readWrite(ProgressWindow progress, DataOutput out, int size, byte[] buffer) { if (size == 0) return 0; try { in.readFully(buffer, 0, size); if (size != BUFFERSIZE) progress.setText("Finishing up the transfer.."); out.write(buffer, 0, size); } catch (Exception ex) { progress.setText("Transmission error!"); System.out.println("Transmission error"); return -1; } bytesSent += size; progress.setText("Transfered: " + Util.getStringFromBytes(bytesSent), FileProgressWindow.BAR_1); progress.setValue(bytesSent + amountToSkip, FileProgressWindow.BAR_1); return size; }
private int writeStrings(DataOutput payload, ByteBuffer offsets, boolean shrink) throws IOException { int stringOffset = 0; Map<String, Integer> used = new HashMap<>(); // Keeps track of strings already written for (String string : strings) { // Dedupe everything except stylized strings, unless shrink is true (then dedupe everything) if (used.containsKey(string) && (shrink || isOriginalDeduped)) { Integer offset = used.get(string); offsets.putInt(offset == null ? 0 : offset); } else { byte[] encodedString = ResourceString.encodeString(string, getStringType()); payload.write(encodedString); used.put(string, stringOffset); offsets.putInt(stringOffset); stringOffset += encodedString.length; } } // ARSC files pad to a 4-byte boundary. We should do so too. stringOffset = writePad(payload, stringOffset); return stringOffset; }
/** * Save SnapshotDiff list for an INodeDirectoryWithSnapshot. * @param sNode The directory that the SnapshotDiff list belongs to. * @param out The {@link DataOutput} to write. */ private static <N extends INode, A extends INodeAttributes, D extends AbstractINodeDiff<N, A, D>> void saveINodeDiffs(final AbstractINodeDiffList<N, A, D> diffs, final DataOutput out, ReferenceMap referenceMap) throws IOException { // Record the diffs in reversed order, so that we can find the correct // reference for INodes in the created list when loading the FSImage if (diffs == null) { out.writeInt(-1); // no diffs } else { final List<D> list = diffs.asList(); final int size = list.size(); out.writeInt(size); for (int i = size - 1; i >= 0; i--) { list.get(i).write(out, referenceMap); } } }
/** * test BlackListInfo class * * @throws IOException */ @Test (timeout=5000) public void testBlackListInfo() throws IOException { BlackListInfo info = new BlackListInfo(); info.setBlackListReport("blackListInfo"); info.setReasonForBlackListing("reasonForBlackListing"); info.setTrackerName("trackerName"); ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); DataOutput out = new DataOutputStream(byteOut); info.write(out); BlackListInfo info2 = new BlackListInfo(); info2.readFields(new DataInputStream(new ByteArrayInputStream(byteOut .toByteArray()))); assertEquals(info, info); assertEquals(info.toString(), info.toString()); assertEquals(info.getTrackerName(), "trackerName"); assertEquals(info.getReasonForBlackListing(), "reasonForBlackListing"); assertEquals(info.getBlackListReport(), "blackListInfo"); }
@Override public void write(DataOutput out) throws IOException { super.write(out); // Write out the number of entries in the map out.writeInt(instance.size()); // Then write out each key/value pair for (Map.Entry<WritableComparable, Writable> e: instance.entrySet()) { out.writeByte(getId(e.getKey().getClass())); e.getKey().write(out); out.writeByte(getId(e.getValue().getClass())); e.getValue().write(out); } }
@Override public void toData(DataOutput out) throws IOException { out.writeBoolean(isRequestForEntireConfiguration); int size = groups.size(); out.writeInt(size); if (size > 0) { for (String group : groups) { out.writeUTF(group); } } out.writeInt(numAttempts); }
/** * Construct an instance of the NBT factory by deducing the class of NBTBase. */ private NbtFactory() { if (BASE_CLASS == null) { try { // Keep in mind that I do use hard-coded field names - but it's okay as long as we're dealing // with CraftBukkit or its derivatives. This does not work in MCPC+ however. ClassLoader loader = NbtFactory.class.getClassLoader(); String packageName = getPackageName(); Class<?> offlinePlayer = loader.loadClass(packageName + ".CraftOfflinePlayer"); // Prepare NBT COMPOUND_CLASS = getMethod(0, Modifier.STATIC, offlinePlayer, "getData").getReturnType(); BASE_CLASS = COMPOUND_CLASS.getSuperclass(); NBT_GET_TYPE = getMethod(0, Modifier.STATIC, BASE_CLASS, "getTypeId"); NBT_CREATE_TAG = getMethod(Modifier.STATIC, 0, BASE_CLASS, "createTag", byte.class); // Prepare CraftItemStack CRAFT_STACK = loader.loadClass(packageName + ".inventory.CraftItemStack"); CRAFT_HANDLE = getField(null, CRAFT_STACK, "handle"); STACK_TAG = getField(null, CRAFT_HANDLE.getType(), "tag"); // Loading/saving String nmsPackage = BASE_CLASS.getPackage().getName(); initializeNMS(loader, nmsPackage); LOAD_COMPOUND = READ_LIMITER_CLASS != null ? new LoadMethodSkinUpdate(STREAM_TOOLS, READ_LIMITER_CLASS) : new LoadMethodWorldUpdate(STREAM_TOOLS); SAVE_COMPOUND = getMethod(Modifier.STATIC, 0, STREAM_TOOLS, null, BASE_CLASS, DataOutput.class); } catch (ClassNotFoundException e) { throw new IllegalStateException("Unable to find offline player.", e); } } }
@Override protected void writePayload(DataOutput output, ByteBuffer header, boolean shrink) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteBuffer offsets = ByteBuffer.allocate(getOffsetSize()).order(ByteOrder.LITTLE_ENDIAN); try (LittleEndianDataOutputStream payload = new LittleEndianDataOutputStream(baos)) { writeEntries(payload, offsets, shrink); } output.write(offsets.array()); output.write(baos.toByteArray()); }
/** * Writes just the bloom filter to the output array * @param out OutputStream to place bloom * @throws IOException Error writing bloom array */ public void writeBloom(final DataOutput out) throws IOException { if (!this.bloom.hasArray()) { throw new IOException("Only writes ByteBuffer with underlying array."); } out.write(bloom.array(), bloom.arrayOffset(), bloom.limit()); }
@Override public void toData(DataOutput out) throws IOException { super.toData(out); DataSerializer.writeObject(this.eventID, out); DataSerializer.writePrimitiveInt(this.serialNum, out); DataSerializer.writePrimitiveBoolean(this.notifyOfRegionDeparture, out); DataSerializer.writeHashMap(this.subregionSerialNumbers, out); }
public void toData(DataOutput out) throws IOException { DataSerializer.writeString(this.fieldName, out); out.writeInt(this.fieldIndex); out.writeInt(this.varLenFieldSeqId); DataSerializer.writeEnum(this.type, out); out.writeInt(this.relativeOffset); out.writeInt(this.vlfOffsetIndex); { // pre 8.1 we wrote a single boolean // 8.1 and after we write a byte whose bits are: // 1: identityField // 2: deleted byte bits = 0; if (this.identityField) { bits |= IDENTITY_BIT; } // Note that this code attempts to only set the DELETED_BIT // if serializing for 8.1 or later. // But in some cases 8.1 serialized data may be sent to a pre 8.1 member. // In that case if this bit is set it will cause the pre 8.1 member // to set identityField to true. // For this reason the pdx delete-field command should only be used after // all member have been upgraded to 8.1 or later. Version sourceVersion = InternalDataSerializer.getVersionForDataStream(out); if (sourceVersion.compareTo(Version.GFE_81) >= 0) { if (this.deleted) { bits |= DELETED_BIT; } } out.writeByte(bits); } }
@Override public void toData(DataOutput out) throws IOException { super.toData(out); out.writeInt(this.bucketId); out.writeBoolean(this.isRebalance); out.writeBoolean(this.replaceOfflineData); out.writeBoolean(this.moveSource != null); if (this.moveSource != null) { InternalDataSerializer.invokeToData(this.moveSource, out); } out.writeBoolean(this.forceCreation); }
@Test public void testSendUnreliably() throws Exception { for (int i = 0; i < 2; i++) { boolean enableMcast = (i == 1); initMocks(enableMcast); InternalDistributedMember mbr = createAddress(8888); DistributedCacheOperation.CacheOperationMessage msg = mock(DistributedCacheOperation.CacheOperationMessage.class); when(msg.getRecipients()).thenReturn(new InternalDistributedMember[] {mbr}); when(msg.getMulticast()).thenReturn(enableMcast); if (!enableMcast) { // for non-mcast we send a message with a reply-processor when(msg.getProcessorId()).thenReturn(1234); } else { // for mcast we send a direct-ack message and expect the messenger // to register it stub(msg.isDirectAck()).toReturn(true); } when(msg.getDSFID()).thenReturn((int) DataSerializableFixedID.PUT_ALL_MESSAGE); interceptor.collectMessages = true; try { messenger.sendUnreliably(msg); } catch (GemFireIOException e) { fail("expected success"); } if (enableMcast) { verify(msg, atLeastOnce()).registerProcessor(); } verify(msg).toData(isA(DataOutput.class)); assertTrue("expected 1 message but found " + interceptor.collectedMessages, interceptor.collectedMessages.size() == 1); assertTrue(interceptor.collectedMessages.get(0).isFlagSet(Message.Flag.NO_RELIABILITY)); } }
public void toDataPre_GFE_8_0_0_0(DataOutput out) throws IOException { super.toData(out); DataSerializer.writeString(Id, out); out.writeLong(startTime); out.writeInt(remoteDSId); out.writeBoolean(isRunning); out.writeBoolean(isPrimary); out.writeBoolean(isParallel); out.writeBoolean(isBatchConflationEnabled); out.writeBoolean(isPersistenceEnabled); out.writeInt(alertThreshold); out.writeBoolean(manualStart); DataSerializer.writeArrayList(eventFiltersClassNames, out); DataSerializer.writeArrayList(transFiltersClassNames, out); DataSerializer.writeArrayList(senderEventListenerClassNames, out); out.writeBoolean(isDiskSynchronous); // out.writeInt(dispatcherThreads); if (isParallel) out.writeInt(1);// it was 1 on previous version of gemfire else if (orderPolicy == null) out.writeInt(1);// it was 1 on previous version of gemfire else out.writeInt(dispatcherThreads); if (isParallel) DataSerializer.writeObject(null, out); else DataSerializer.writeObject(orderPolicy, out); boolean serverLocationFound = (this.serverLocation != null); DataSerializer.writePrimitiveBoolean(serverLocationFound, out); if (serverLocationFound) { InternalDataSerializer.invokeToData(serverLocation, out); } }
/** * Write a String as a VInt n, followed by n Bytes as in Text format. * * @param out * @param s * @throws IOException */ public static void writeString(DataOutput out, String s) throws IOException { if (s != null) { Text text = new Text(s); byte[] buffer = text.getBytes(); int len = text.getLength(); writeVInt(out, len); out.write(buffer, 0, len); } else { writeVInt(out, -1); } }
public void toDataPre_GFE_7_1_0_0(DataOutput out) throws IOException { int size = this.serverFilterInfo.size(); out.writeInt(size); for (Map.Entry<InternalDistributedMember, FilterInfo> e : this.serverFilterInfo.entrySet()) { InternalDistributedMember member = e.getKey(); InternalDataSerializer.invokeToData(member, out); FilterInfo fInfo = e.getValue(); InternalDataSerializer.invokeToData(fInfo, out); } }
private void writeChars(DataOutput out, String value) throws IOException { if (value!=null) { text.set(value); }else { text.set(""); } text.write(out); }
private void write2DArray(DataOutput out, float[][] f) throws IOException { for(int i=0;i<f.length;i++){ float[] g=f[i]; for(int j=0;j<g.length;j++){ out.writeFloat(g[j]); } } }
/** Write a UTF8 encoded string with a maximum size to out */ public static int writeString(DataOutput out, String s, int maxLength) throws IOException { ByteBuffer bytes = encode(s); int length = bytes.limit(); if (length > maxLength) { throw new IOException("string was too long to write! Expected " + "less than or equal to " + maxLength + " bytes, but got " + length + " bytes."); } WritableUtils.writeVInt(out, length); out.write(bytes.array(), 0, length); return length; }
/** * Write the actual data contents of the tag, implemented in NBT extension classes */ void write(DataOutput output) throws IOException { output.writeInt(this.intArray.length); for (int i = 0; i < this.intArray.length; ++i) { output.writeInt(this.intArray[i]); } }
/** * Writes the state the ZoneOffset to the stream. * * @param offset the offset, not null * @param out the output stream, not null * @throws IOException if an error occurs */ static void writeOffset(ZoneOffset offset, DataOutput out) throws IOException { final int offsetSecs = offset.getTotalSeconds(); int offsetByte = offsetSecs % 900 == 0 ? offsetSecs / 900 : 127; // compress to -72 to +72 out.writeByte(offsetByte); if (offsetByte == 127) { out.writeInt(offsetSecs); } }
public void toData(DataOutput out) throws IOException { out.writeInt(size()); ObjectTypeImpl ctImpl = (ObjectTypeImpl) this.getCollectionType().getElementType(); Assert.assertTrue(ctImpl != null, "ctImpl can not be null"); InternalDataSerializer.invokeToData(ctImpl, out); for (Iterator itr = this.iterator(); itr.hasNext();) { DataSerializer.writeObject(itr.next(), out); } }
@VisibleForTesting void writeImpl(DataOutput out) throws IOException { out.writeByte(VERSION); owner.write(out); renewer.write(out); realUser.write(out); WritableUtils.writeVLong(out, issueDate); WritableUtils.writeVLong(out, maxDate); WritableUtils.writeVInt(out, sequenceNumber); WritableUtils.writeVInt(out, masterKeyId); }
@Override public void write(DataOutput out) throws IOException { //TODO Write resources version no too WritableUtils.writeVLong(out, cumulativeCpuUsage); // long #1 WritableUtils.writeVLong(out, cumulativeGpuUsage); WritableUtils.writeVLong(out, virtualMemoryUsage); // long #2 WritableUtils.writeVLong(out, physicalMemoryUsage); // long #3 WritableUtils.writeVLong(out, heapUsage); // long #4 }
/** * Serialize a {@link PermissionStatus} from its base components. */ public static void write(DataOutput out, String username, String groupname, FsPermission permission) throws IOException { Text.writeString(out, username, Text.DEFAULT_MAX_LEN); Text.writeString(out, groupname, Text.DEFAULT_MAX_LEN); permission.write(out); }
/** * Writes the type code for a primitive type Class to <code>DataOutput</code>. */ public static final void writePrimitiveClass(Class c, DataOutput out) throws IOException { if (c == Boolean.TYPE) { out.writeByte(BOOLEAN_TYPE); } else if (c == Character.TYPE) { out.writeByte(CHARACTER_TYPE); } else if (c == Byte.TYPE) { out.writeByte(BYTE_TYPE); } else if (c == Short.TYPE) { out.writeByte(SHORT_TYPE); } else if (c == Integer.TYPE) { out.writeByte(INTEGER_TYPE); } else if (c == Long.TYPE) { out.writeByte(LONG_TYPE); } else if (c == Float.TYPE) { out.writeByte(FLOAT_TYPE); } else if (c == Double.TYPE) { out.writeByte(DOUBLE_TYPE); } else if (c == Void.TYPE) { out.writeByte(VOID_TYPE); } else if (c == null) { out.writeByte(NULL); } else { throw new InternalGemFireError( LocalizedStrings.InternalDataSerializer_UNKNOWN_PRIMITIVE_TYPE_0 .toLocalizedString(c.getName())); } }
public static void writeBigInteger(BigInteger o, DataOutput out) throws IOException { InternalDataSerializer.checkOut(out); if (logger.isTraceEnabled(LogMarker.SERIALIZER)) { logger.trace(LogMarker.SERIALIZER, "Writing BigInteger: {}", o); } DataSerializer.writeByteArray(o.toByteArray(), out); }
private static void writeTag(NBTBase p_150663_0_, DataOutput p_150663_1_) throws IOException { p_150663_1_.writeByte(p_150663_0_.getId()); if (p_150663_0_.getId() != 0) { p_150663_1_.writeUTF(""); p_150663_0_.write(p_150663_1_); } }
@Override public void toData(DataOutput out) throws IOException { /** * first write the total list size then in a loop write the region name, number of eventIds and * the event ids * */ super.toData(out); // write the size of the data list DataSerializer.writeInteger(Integer.valueOf(this.messagesList.size()), out); Iterator iterator = messagesList.iterator(); String regionName = null; Integer numberOfIds = null; Object eventId = null; int maxVal; while (iterator.hasNext()) { regionName = (String) iterator.next(); // write the regionName DataSerializer.writeString(regionName, out); numberOfIds = (Integer) iterator.next(); // write the number of event ids DataSerializer.writeInteger(numberOfIds, out); maxVal = numberOfIds.intValue(); // write the event ids for (int i = 0; i < maxVal; i++) { eventId = iterator.next(); DataSerializer.writeObject(eventId, out); } } }
@Override public void write(DataOutput out) throws IOException { out.writeInt(this.id); out.writeInt(this.year); out.writeInt(this.season); out.writeInt(this.month); out.writeInt(this.week); out.writeInt(this.day); out.writeUTF(this.type); out.writeLong(this.calendar.getTime()); }
public void write(DataOutput out) throws IOException { taskId.write(out); WritableUtils.writeVInt(out, idWithinJob); out.writeBoolean(isMap); WritableUtils.writeEnum(out, status); WritableUtils.writeString(out, taskTrackerHttp); WritableUtils.writeVInt(out, taskRunTime); WritableUtils.writeVInt(out, eventId); }
@Override public void write(DataOutput out) throws IOException { out.writeLong(version); if (methods == null) { out.writeBoolean(false); } else { out.writeBoolean(true); out.writeInt(methods.length); for (int method : methods) { out.writeInt(method); } } }
@Override public void toData(DataOutput out) throws IOException { DataSerializer.writeByte(op.ordinalByte(), out); DataSerializer.writeLong(timestamp, out); DataSerializer.writeObject(condition, out); DataSerializer.writeArrayList((ArrayList) columnList, out); }