Java Code Examples for java.io.DataOutput#write()

The following examples show how to use java.io.DataOutput#write() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HybridMemorySegment.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public final void get(DataOutput out, int offset, int length) throws IOException {
	if (address <= addressLimit) {
		if (heapMemory != null) {
			out.write(heapMemory, offset, length);
		}
		else {
			while (length >= 8) {
				out.writeLong(getLongBigEndian(offset));
				offset += 8;
				length -= 8;
			}

			while (length > 0) {
				out.writeByte(get(offset));
				offset++;
				length--;
			}
		}
	}
	else {
		throw new IllegalStateException("segment has been freed");
	}
}
 
Example 2
Source File: BloomFilter.java    From RDFS with Apache License 2.0 6 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
  super.write(out);
  byte[] bytes = new byte[getNBytes()];
  for(int i = 0, byteIndex = 0, bitIndex = 0; i < vectorSize; i++, bitIndex++) {
    if (bitIndex == 8) {
      bitIndex = 0;
      byteIndex++;
    }
    if (bitIndex == 0) {
      bytes[byteIndex] = 0;
    }
    if (bits.get(i)) {
      bytes[byteIndex] |= bitvalues[bitIndex];
    }
  }
  out.write(bytes);
}
 
Example 3
Source File: SubtractOperation.java    From vxquery with Apache License 2.0 6 votes vote down vote up
@Override
public void operateDateDTDuration(XSDatePointable datep1, LongPointable longp2, DataOutput dOut)
        throws SystemException, IOException {
    // Add duration.
    abvsInner1.reset();
    DateTime.normalizeDateTime(datep1.getYearMonth(), datep1.getDayTime() - longp2.getLong(),
            datep1.getTimezoneHour(), datep1.getTimezoneMinute(), dOutInner1);
    byte[] bytes = abvsInner1.getByteArray();
    int startOffset = abvsInner1.getStartOffset() + 1;
    // Convert to date.
    bytes[startOffset + XSDatePointable.TIMEZONE_HOUR_OFFSET] = bytes[startOffset
            + XSDateTimePointable.TIMEZONE_HOUR_OFFSET];
    bytes[startOffset + XSDatePointable.TIMEZONE_MINUTE_OFFSET] = bytes[startOffset
            + XSDateTimePointable.TIMEZONE_MINUTE_OFFSET];
    dOut.write(ValueTag.XS_DATE_TAG);
    dOut.write(bytes, startOffset, XSDatePointable.TYPE_TRAITS.getFixedLength());
}
 
Example 4
Source File: DivideOperation.java    From vxquery with Apache License 2.0 5 votes vote down vote up
@Override
public void operateFloatDecimal(FloatPointable floatp1, XSDecimalPointable decp2, DataOutput dOut)
        throws SystemException, IOException {
    if (decp2.getDecimalValue() == 0) {
        throw new SystemException(ErrorCode.FOAR0001);
    }
    float value = floatp1.floatValue();
    value /= decp2.floatValue();
    dOut.write(ValueTag.XS_FLOAT_TAG);
    dOut.writeDouble(value);
}
 
Example 5
Source File: ChunkWithChunks.java    From android-chunk-utils with Apache License 2.0 5 votes vote down vote up
@Override
protected void writePayload(DataOutput output, ByteBuffer header, boolean shrink)
    throws IOException {
  for (Chunk chunk : getChunks().values()) {
    byte[] chunkBytes = chunk.toByteArray(shrink);
    output.write(chunkBytes);
    writePad(output, chunkBytes.length);
  }
}
 
Example 6
Source File: SubtractOperation.java    From vxquery with Apache License 2.0 5 votes vote down vote up
@Override
public void operateDTDurationFloat(LongPointable longp, FloatPointable floatp, DataOutput dOut)
        throws SystemException, IOException {
    long value = longp.longValue();
    value -= floatp.longValue();
    dOut.write(ValueTag.XS_DAY_TIME_DURATION_TAG);
    dOut.writeLong(value);
}
 
Example 7
Source File: Record.java    From stratosphere with Apache License 2.0 5 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
	// make sure everything is in a valid binary representation
	updateBinaryRepresenation();
	
	// write the length first, variably encoded, then the contents of the binary array
	writeVarLengthInt(out, this.binaryLen);
	out.write(this.binaryData, 0, this.binaryLen);
}
 
Example 8
Source File: StreamUtil.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
public static void writeString(DataOutput output, String s) throws IOException {
  try {
    byte[] bs = s.getBytes(UTF_8);
    output.writeInt(bs.length);
    output.write(bs);
  } catch (UnsupportedEncodingException e) {
    throw new RuntimeException("Does not supported UTF-8?", e);
  }
}
 
Example 9
Source File: RandomAccessFileTest.java    From jcifs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @param bufSize
 * @param length
 * @param os
 * @throws IOException
 */
static void writeRandom ( int bufSize, long length, DataOutput os ) throws IOException {
    long start = System.currentTimeMillis();
    byte buffer[] = new byte[bufSize];
    long p = 0;
    Random r = ReadWriteTest.getRandom();
    while ( p < length ) {
        ReadWriteTest.randBytes(r, buffer);
        int w = Math.min(bufSize, (int) ( length - p ));
        os.write(buffer, 0, w);
        p += w;
    }
    log.debug("Write " + length + " took " + ( System.currentTimeMillis() - start ));
}
 
Example 10
Source File: GoogleHadoopFileSystemBase.java    From hadoop-connectors with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
  out.write(bytes);
}
 
Example 11
Source File: CastableAsIntegerOperation.java    From vxquery with Apache License 2.0 4 votes vote down vote up
public void convertInt(IntegerPointable intp, DataOutput dOut) throws SystemException, IOException {
    dOut.write(ValueTag.XS_BOOLEAN_TAG);
    dOut.write((byte) 1);
}
 
Example 12
Source File: CastableAsBase64BinaryOperation.java    From vxquery with Apache License 2.0 4 votes vote down vote up
@Override
public void convertHexBinary(XSBinaryPointable binaryp, DataOutput dOut) throws SystemException, IOException {
    dOut.write(ValueTag.XS_BOOLEAN_TAG);
    dOut.write((byte) 1);
}
 
Example 13
Source File: BytesRefWritable.java    From tajo with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public void write(DataOutput out) throws IOException {
  lazyDecompress();
  out.writeInt(length);
  out.write(bytes, start, length);
}
 
Example 14
Source File: CastToNotationOperation.java    From vxquery with Apache License 2.0 4 votes vote down vote up
@Override
public void convertNotation(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
    dOut.write(ValueTag.XS_NOTATION_TAG);
    dOut.write(stringp.getByteArray(), stringp.getStartOffset(), stringp.getLength());
}
 
Example 15
Source File: CastToBase64BinaryOperation.java    From vxquery with Apache License 2.0 4 votes vote down vote up
@Override
public void convertBase64Binary(XSBinaryPointable binaryp, DataOutput dOut) throws SystemException, IOException {
    dOut.write(ValueTag.XS_BASE64_BINARY_TAG);
    dOut.write(binaryp.getByteArray(), binaryp.getStartOffset(), binaryp.getLength());
}
 
Example 16
Source File: StringValue.java    From flink with Apache License 2.0 4 votes vote down vote up
public static final void writeString(CharSequence cs, DataOutput out) throws IOException {
	if (cs != null) {
		int strlen = cs.length();

		// the length we write is offset by one, because a length of zero indicates a null value
		int lenToWrite = strlen + 1;
		if (lenToWrite < 0) {
			throw new IllegalArgumentException("CharSequence is too long.");
		}

		// string is prefixed by it's variable length encoded size, which can take 1-5 bytes.
		if (lenToWrite < HIGH_BIT) {
			out.write((byte) lenToWrite);
		} else if (lenToWrite < HIGH_BIT14) {
			out.write((lenToWrite | HIGH_BIT));
			out.write((lenToWrite >>> 7));
		} else if (lenToWrite < HIGH_BIT21) {
			out.write(lenToWrite | HIGH_BIT);
			out.write((lenToWrite >>> 7) | HIGH_BIT);
			out.write((lenToWrite >>> 14));
		} else if (lenToWrite < HIGH_BIT28) {
			out.write(lenToWrite | HIGH_BIT);
			out.write((lenToWrite >>> 7) | HIGH_BIT);
			out.write((lenToWrite >>> 14) | HIGH_BIT);
			out.write((lenToWrite >>> 21));
		} else {
			out.write(lenToWrite | HIGH_BIT);
			out.write((lenToWrite >>> 7) | HIGH_BIT);
			out.write((lenToWrite >>> 14) | HIGH_BIT);
			out.write((lenToWrite >>> 21) | HIGH_BIT);
			out.write((lenToWrite >>> 28));
		}

		// write the char data, variable length encoded
		for (int i = 0; i < strlen; i++) {
			int c = cs.charAt(i);

			// manual loop unroll, as it performs much better on jdk8
			if (c < HIGH_BIT) {
				out.write(c);
			} else if (c < HIGH_BIT14) {
				out.write(c | HIGH_BIT);
				out.write((c >>> 7));
			} else {
				out.write(c | HIGH_BIT);
				out.write((c >>> 7) | HIGH_BIT);
				out.write((c >>> 14));
			}
		}
	} else {
		out.write(0);
	}
}
 
Example 17
Source File: TrieDictionary.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
    out.write(trieBytes);
}
 
Example 18
Source File: CastableAsStringOperation.java    From vxquery with Apache License 2.0 4 votes vote down vote up
@Override
public void convertDate(XSDatePointable datep, DataOutput dOut) throws SystemException, IOException {
    dOut.write(ValueTag.XS_BOOLEAN_TAG);
    dOut.write((byte) 1);
}
 
Example 19
Source File: CastableAsYMDurationOperation.java    From vxquery with Apache License 2.0 4 votes vote down vote up
@Override
public void convertDuration(XSDurationPointable durationp, DataOutput dOut) throws SystemException, IOException {
    dOut.write(ValueTag.XS_BOOLEAN_TAG);
    dOut.write((byte) 1);
}
 
Example 20
Source File: IdentityAddressProtocolUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static void write(final DataOutput output, final SecurityIdentity securityIdentity, final InetAddress sourceAddress) throws IOException {
    final Principal principal;
    final String realm;
    final Set<String> roles;
    if (securityIdentity != null) {
        principal = securityIdentity.getPrincipal();
        realm = principal instanceof RealmPrincipal ? ((RealmPrincipal) principal).getRealm() : null;
        roles = StreamSupport.stream(securityIdentity.getRoles().spliterator(), false).collect(Collectors.toSet());
    } else {
        principal = null;
        realm = null;
        roles = Collections.emptySet();
    }

    int itemsToSend = (principal != null ? 1 : 0) + roles.size() + (sourceAddress != null ? 1 : 0);

    output.writeByte(ModelControllerProtocol.PARAM_IDENTITY_LENGTH);
    if (itemsToSend == 0) {
        output.writeInt(0);
        return;
    }

    output.writeInt(1); // We have one batch of identity related items to send.
    output.write(ITEMS_PARAM);
    output.writeInt(itemsToSend); // Number of items being written.

    if (principal != null) {
        output.write(USER);
        if (realm != null) {
            output.write(REALM_PARAM);
            output.writeUTF(realm);
        }
        output.write(NAME_PARAM);
        output.writeUTF(principal.getName());
    }

    // We send all the SI roles as groups as previous versions would map from group to access control role.
    for (String roleName : roles) {
        output.write(GROUP);
        if (realm != null) {
            // We write the realm as older hosts use it - servers build on WildFly Core 3 will just drop it.
            output.write(REALM_PARAM);
            output.writeUTF(realm);
        }
        output.write(NAME_PARAM);
        output.writeUTF(roleName);

        // We could also send each one as ROLE but for now don't.
        // If we later send each as a role - do not include the realm as older clients do not expect a realm to be associated with a role.
    }

    if (sourceAddress != null) {
        output.write(INET_ADDRESS);

        String host = sourceAddress.getHostName();
        byte[] addr = sourceAddress.getAddress();

        output.write(HOST_PARAM);
        output.writeUTF(host);
        output.write(ADDR_PARAM);
        output.writeInt(addr.length);
        output.write(addr);
    }
}