當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteArrayDataOutput.write方法代碼示例

本文整理匯總了Java中com.google.common.io.ByteArrayDataOutput.write方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteArrayDataOutput.write方法的具體用法?Java ByteArrayDataOutput.write怎麽用?Java ByteArrayDataOutput.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.io.ByteArrayDataOutput的用法示例。


在下文中一共展示了ByteArrayDataOutput.write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: encodeString

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
/**
 * Encodes a string in either UTF-8 or UTF-16 and returns the bytes of the encoded string.
 * Strings are prefixed by 2 values. The first is the number of characters in the string.
 * The second is the encoding length (number of bytes in the string).
 *
 * <p>Here's an example UTF-8-encoded string of ab©:
 * <pre>03 04 61 62 C2 A9 00</pre>
 *
 * @param str  The string to be encoded.
 * @param type The encoding type that the {@link ResourceString} should be encoded in.
 * @return The encoded string.
 */
public static byte[] encodeString(String str, Type type) {
    byte[] bytes = str.getBytes(type.charset());
    // The extra 5 bytes is for metadata (character count + byte count) and the NULL terminator.
    ByteArrayDataOutput output = ByteStreams.newDataOutput(bytes.length + 5);
    encodeLength(output, str.length(), type);
    if (type == Type.UTF8) {  // Only UTF-8 strings have the encoding length.
        encodeLength(output, bytes.length, type);
    }
    output.write(bytes);
    // NULL-terminate the string
    if (type == Type.UTF8) {
        output.write(0);
    } else {
        output.writeShort(0);
    }
    return output.toByteArray();
}
 
開發者ID:CalebFenton,項目名稱:apkfile,代碼行數:30,代碼來源:ResourceString.java

示例2: encodeLength

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
private static void encodeLength(ByteArrayDataOutput output, int length, Type type) {
    if (length < 0) {
        output.write(0);
        return;
    }
    if (type == Type.UTF8) {
        if (length > 0x7F) {
            output.write(((length & 0x7F00) >> 8) | 0x80);
        }
        output.write(length & 0xFF);
    } else {  // UTF-16
        // TODO(acornwall): Replace output with a little-endian output.
        if (length > 0x7FFF) {
            int highBytes = ((length & 0x7FFF0000) >> 16) | 0x8000;
            output.write(highBytes & 0xFF);
            output.write((highBytes & 0xFF00) >> 8);
        }
        int lowBytes = length & 0xFFFF;
        output.write(lowBytes & 0xFF);
        output.write((lowBytes & 0xFF00) >> 8);
    }
}
 
開發者ID:CalebFenton,項目名稱:apkfile,代碼行數:23,代碼來源:ResourceString.java

示例3: encodeString

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
/**
 * Encodes a string in either UTF-8 or UTF-16 and returns the bytes of the encoded string.
 * Strings are prefixed by 2 values. The first is the number of characters in the string.
 * The second is the encoding length (number of bytes in the string).
 *
 * <p>Here's an example UTF-8-encoded string of ab©:
 * <pre>03 04 61 62 C2 A9 00</pre>
 *
 * @param str The string to be encoded.
 * @param type The encoding type that the {@link ResourceString} should be encoded in.
 * @return The encoded string.
 */
public static byte[] encodeString(String str, Type type) {
  byte[] bytes = str.getBytes(type.charset());
  // The extra 5 bytes is for metadata (character count + byte count) and the NULL terminator.
  ByteArrayDataOutput output = ByteStreams.newDataOutput(bytes.length + 5);
  encodeLength(output, str.length(), type);
  if (type == Type.UTF8) {  // Only UTF-8 strings have the encoding length.
    encodeLength(output, bytes.length, type);
  }
  output.write(bytes);
  // NULL-terminate the string
  if (type == Type.UTF8) {
    output.write(0);
  } else {
    output.writeShort(0);
  }
  return output.toByteArray();
}
 
開發者ID:madisp,項目名稱:android-chunk-utils,代碼行數:30,代碼來源:ResourceString.java

示例4: encodeLength

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
private static void encodeLength(ByteArrayDataOutput output, int length, Type type) {
  if (length < 0) {
    output.write(0);
    return;
  }
  if (type == Type.UTF8) {
    if (length > 0x7F) {
      output.write(((length & 0x7F00) >> 8) | 0x80);
    }
    output.write(length & 0xFF);
  } else {  // UTF-16
    // TODO(acornwall): Replace output with a little-endian output.
    if (length > 0x7FFF) {
      int highBytes = ((length & 0x7FFF0000) >> 16) | 0x8000;
      output.write(highBytes & 0xFF);
      output.write((highBytes & 0xFF00) >> 8);
    }
    int lowBytes = length & 0xFFFF;
    output.write(lowBytes & 0xFF);
    output.write((lowBytes & 0xFF00) >> 8);
  }
}
 
開發者ID:madisp,項目名稱:android-chunk-utils,代碼行數:23,代碼來源:ResourceString.java

示例5: sendSignUpdateRequest

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
public static void sendSignUpdateRequest(Game game) {
	ByteArrayDataOutput out = ByteStreams.newDataOutput();
	String name = SkyWarsReloaded.getCfg().getBungeeServer();
	try {
		out.writeUTF("Forward");
		out.writeUTF("ALL");
		out.writeUTF("SkyWarsReloaded");

		ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
		DataOutputStream msgout = new DataOutputStream(msgbytes);
		msgout.writeUTF(name + ":" + game.getState().toString() + ":" + Integer.toString(game.getPlayers().size()) + ":" + Integer.toString(game.getNumberOfSpawns()) + ":" + game.getMapName());

		out.writeShort(msgbytes.toByteArray().length);
		out.write(msgbytes.toByteArray());

		Bukkit.getServer().sendPluginMessage(SkyWarsReloaded.get(), "BungeeCord", out.toByteArray());
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:smessie,項目名稱:SkyWarsReloaded,代碼行數:21,代碼來源:BungeeUtil.java

示例6: readLine

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
private String readLine() throws IOException {

        ByteArrayDataOutput out = ByteStreams.newDataOutput(300);
        int i = 0;
        int c;
        while ((c = raf.read()) != -1) {
            i++;
            out.write((byte) c);
            if (c == LINE_SEP.charAt(0)) {
                break;
            }
        }
        if (i == 0) {
            return null;
        }
        return new String(out.toByteArray(), Charsets.UTF_8);
    }
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:18,代碼來源:TailFile.java

示例7: findShortSuccessor

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Override
public Slice findShortSuccessor(Slice key) {
    Slice userKey = extractUserKey(key);
    Slice tmp = userComparator.findShortSuccessor(userKey);
    if (tmp.size() < userKey.size() && userComparator.compare(userKey, tmp) < 0) {
        ByteArrayDataOutput buffer = ByteStreams.newDataOutput();
        buffer.write(tmp.data(), 0, tmp.size());
        try {
            Coding.putFixed64(buffer, packSequenceAndType(MAX_SEQUENCE_NUMBER, VALUE_TYPE_FOR_SEEK));
        } catch (IOException e) {
            // should never exception
            return key;
        }
        tmp = new Slice(buffer.toByteArray());
        Preconditions.checkState(compare(key, tmp) < 0);
        return tmp;
    }
    return key;
}
 
開發者ID:zxl0714,項目名稱:leveldb-sstable,代碼行數:20,代碼來源:DBFormat.java

示例8: findShortestSeparator

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Override
public Slice findShortestSeparator(Slice start, Slice limit) {
    Slice userStart = extractUserKey(start);
    Slice userLimit = extractUserKey(limit);
    Slice tmp = userComparator.findShortestSeparator(userStart, userLimit);
    if (tmp.size() < userStart.size() && userComparator.compare(userStart, tmp) < 0) {
        ByteArrayDataOutput buffer = ByteStreams.newDataOutput();
        buffer.write(tmp.data(), 0, tmp.size());
        try {
            Coding.putFixed64(buffer, packSequenceAndType(MAX_SEQUENCE_NUMBER, VALUE_TYPE_FOR_SEEK));
        } catch (IOException e) {
            // should never exception
            return start;
        }
        tmp = new Slice(buffer.toByteArray());
        Preconditions.checkState(compare(start, tmp) < 0);
        Preconditions.checkState(compare(tmp, limit) < 0);
        return tmp;
    }
    return start;
}
 
開發者ID:zxl0714,項目名稱:leveldb-sstable,代碼行數:22,代碼來源:DBFormat.java

示例9: testDeserializeNonConsecutiveDuplicateTags

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Test
public void testDeserializeNonConsecutiveDuplicateTags()
    throws TagContextDeserializationException {
  ByteArrayDataOutput output = ByteStreams.newDataOutput();
  output.write(SerializationUtils.VERSION_ID);
  encodeTagToOutput("Key1", "Value1", output);
  encodeTagToOutput("Key2", "Value2", output);
  encodeTagToOutput("Key3", "Value3", output);
  encodeTagToOutput("Key1", "Value1", output);
  encodeTagToOutput("Key2", "Value2", output);
  TagContext expected =
      tagger
          .emptyBuilder()
          .put(TagKey.create("Key1"), TagValue.create("Value1"))
          .put(TagKey.create("Key2"), TagValue.create("Value2"))
          .put(TagKey.create("Key3"), TagValue.create("Value3"))
          .build();
  assertThat(serializer.fromByteArray(output.toByteArray())).isEqualTo(expected);
}
 
開發者ID:census-instrumentation,項目名稱:opencensus-java,代碼行數:20,代碼來源:TagContextDeserializationTest.java

示例10: testDeserializeNonConsecutiveDuplicateKeys

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Test
public void testDeserializeNonConsecutiveDuplicateKeys()
    throws TagContextDeserializationException {
  ByteArrayDataOutput output = ByteStreams.newDataOutput();
  output.write(SerializationUtils.VERSION_ID);
  encodeTagToOutput("Key1", "Value1", output);
  encodeTagToOutput("Key2", "Value2", output);
  encodeTagToOutput("Key3", "Value3", output);
  encodeTagToOutput("Key1", "Value4", output);
  encodeTagToOutput("Key2", "Value5", output);
  TagContext expected =
      tagger
          .emptyBuilder()
          .put(TagKey.create("Key1"), TagValue.create("Value4"))
          .put(TagKey.create("Key2"), TagValue.create("Value5"))
          .put(TagKey.create("Key3"), TagValue.create("Value3"))
          .build();
  assertThat(serializer.fromByteArray(output.toByteArray())).isEqualTo(expected);
}
 
開發者ID:census-instrumentation,項目名稱:opencensus-java,代碼行數:20,代碼來源:TagContextDeserializationTest.java

示例11: sign

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
public SignResponse sign(DeviceRegistration registeredDevice, SignRequest startedSignature) throws Exception {
    Map<String, String> clientData = new HashMap<String, String>();
    clientData.put("typ", "navigator.id.getAssertion");
    clientData.put("challenge", startedSignature.getChallenge());
    clientData.put("origin", "http://example.com");
    String clientDataJson = objectMapper.writeValueAsString(clientData);


    byte[] clientParam = crypto.hash(clientDataJson);
    byte[] appParam = crypto.hash(startedSignature.getAppId());
    com.yubico.u2f.softkey.messages.SignRequest signRequest = new com.yubico.u2f.softkey.messages.SignRequest((byte) 0x01, clientParam, appParam, U2fB64Encoding.decode(registeredDevice.getKeyHandle()));

    RawSignResponse rawSignResponse = key.sign(signRequest);

    String clientDataBase64 = U2fB64Encoding.encode(clientDataJson.getBytes());
    ByteArrayDataOutput authData = ByteStreams.newDataOutput();
    authData.write(rawSignResponse.getUserPresence());
    authData.writeInt((int) rawSignResponse.getCounter());
    authData.write(rawSignResponse.getSignature());

    return new SignResponse(
            clientDataBase64,
            U2fB64Encoding.encode(authData.toByteArray()),
            startedSignature.getKeyHandle()
    );
}
 
開發者ID:Yubico,項目名稱:java-u2flib-server,代碼行數:27,代碼來源:Client.java

示例12: encodeRegisterResponse

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
public static byte[] encodeRegisterResponse(RawRegisterResponse rawRegisterResponse) throws U2fBadInputException {
    byte[] keyHandle = rawRegisterResponse.keyHandle;
    if (keyHandle.length > 255) {
        throw new U2fBadInputException("keyHandle length cannot be longer than 255 bytes!");
    }

    try {
        ByteArrayDataOutput encoded = ByteStreams.newDataOutput();
        encoded.write(RawRegisterResponse.REGISTRATION_RESERVED_BYTE_VALUE);
        encoded.write(rawRegisterResponse.userPublicKey);
        encoded.write((byte) keyHandle.length);
        encoded.write(keyHandle);
        encoded.write(rawRegisterResponse.attestationCertificate.getEncoded());
        encoded.write(rawRegisterResponse.signature);
        return encoded.toByteArray();
    } catch (CertificateEncodingException e) {
        throw new U2fBadInputException("Error when encoding attestation certificate.", e);
    }
}
 
開發者ID:Yubico,項目名稱:java-u2flib-server,代碼行數:20,代碼來源:CodecTestUtils.java

示例13: keyBytes

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
private byte[][] keyBytes(int[] keys, IBM index) throws Exception {
    byte[][] bytes;
    if (atomized) {
        long[] sizes = bitmaps.serializeAtomizedSizeInBytes(index, keys);
        ByteArrayDataOutput[] dataOutputs = new ByteArrayDataOutput[keys.length];
        for (int i = 0; i < keys.length; i++) {
            dataOutputs[i] = sizes[i] < 0 ? null : ByteStreams.newDataOutput((int) sizes[i]);
        }
        bitmaps.serializeAtomized(index, keys, dataOutputs);
        bytes = new byte[keys.length][];
        for (int i = 0; i < keys.length; i++) {
            bytes[i] = dataOutputs[i] == null ? null : dataOutputs[i].toByteArray();
        }
    } else {
        long size = serializedSizeInBytes(bitmaps, index);
        ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput((int) size);
        dataOutput.write(FilerIO.intBytes(lastId));
        bitmaps.serialize(index, dataOutput);
        bytes = new byte[][] { dataOutput.toByteArray() };
    }
    return bytes;
}
 
開發者ID:jivesoftware,項目名稱:miru,代碼行數:23,代碼來源:LabInvertedIndex.java

示例14: appendPayload

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Override
public void appendPayload(ByteArrayDataOutput out) {
    out.writeUTF(serverName);
    out.writeUTF(channelName);
    out.writeShort(data.length);
    out.write(data);
}
 
開發者ID:lucko,項目名稱:helper,代碼行數:8,代碼來源:BungeeMessaging.java

示例15: toByteArray

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Override
public byte[] toByteArray(boolean shrink) throws IOException {
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    for (Chunk chunk : chunks) {
        output.write(chunk.toByteArray(shrink));
    }
    return output.toByteArray();
}
 
開發者ID:CalebFenton,項目名稱:apkfile,代碼行數:9,代碼來源:ResourceFile.java


注:本文中的com.google.common.io.ByteArrayDataOutput.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。