当前位置: 首页>>代码示例>>Java>>正文


Java DataOutputStream类代码示例

本文整理汇总了Java中java.io.DataOutputStream的典型用法代码示例。如果您正苦于以下问题:Java DataOutputStream类的具体用法?Java DataOutputStream怎么用?Java DataOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DataOutputStream类属于java.io包,在下文中一共展示了DataOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSerialization

import java.io.DataOutputStream; //导入依赖的package包/类
@Test
public void testSerialization() throws Exception {
  Set<PersistentMemberID>[] offlineMembers = new Set[5];
  for (int i = 0; i < offlineMembers.length; i++) {
    offlineMembers[i] = new HashSet<PersistentMemberID>();
    offlineMembers[i].add(new PersistentMemberID(DiskStoreID.random(), InetAddress.getLocalHost(),
        "a", System.currentTimeMillis(), (short) 0));
  }
  OfflineMemberDetailsImpl details = new OfflineMemberDetailsImpl(offlineMembers);

  ByteArrayOutputStream boas = new ByteArrayOutputStream();
  DataOutput out = new DataOutputStream(boas);
  details.toData(out);

  OfflineMemberDetailsImpl details2 = new OfflineMemberDetailsImpl();
  details2.fromData(new DataInputStream(new ByteArrayInputStream(boas.toByteArray())));
}
 
开发者ID:ampool,项目名称:monarch,代码行数:18,代码来源:OfflineMembersDetailsJUnitTest.java

示例2: serialise

import java.io.DataOutputStream; //导入依赖的package包/类
@Override
public void
serialise(
	DataOutputStream	os )

	throws IOException
{
	super.serialise(os);

	os.write( hash );
	os.write( peer_id );
	os.writeLong( downloaded );
	os.writeLong( left );
	os.writeLong( uploaded );
	os.writeInt( event );
	os.writeInt( ip_address );
	os.writeInt( num_want );
	os.writeShort( port );
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:20,代码来源:PRUDPPacketRequestAnnounce.java

示例3: writeToStream

import java.io.DataOutputStream; //导入依赖的package包/类
public void writeToStream(OutputStream gribFile) {
	
	DataOutputStream dataout = new DataOutputStream(gribFile);
	
	try {
		
		gribFile.write(magicnumberbytes);
		dataout.writeShort(reserved);
		gribFile.write(discipline);
		gribFile.write(number);
		dataout.writeLong(totalLength);
		
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:philippphb,项目名称:GRIB2Tools,代码行数:18,代码来源:GribSection0.java

示例4: write

import java.io.DataOutputStream; //导入依赖的package包/类
/**
 * Write the constant to the output stream
 */
void write(Environment env, DataOutputStream out, ConstantPool tab) throws IOException {
    if (num instanceof Integer) {
        out.writeByte(CONSTANT_INTEGER);
        out.writeInt(num.intValue());
    } else if (num instanceof Long) {
        out.writeByte(CONSTANT_LONG);
        out.writeLong(num.longValue());
    } else if (num instanceof Float) {
        out.writeByte(CONSTANT_FLOAT);
        out.writeFloat(num.floatValue());
    } else if (num instanceof Double) {
        out.writeByte(CONSTANT_DOUBLE);
        out.writeDouble(num.doubleValue());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:NumberConstantData.java

示例5: long2VarIntByteArray

import java.io.DataOutputStream; //导入依赖的package包/类
/**
 * Transform a long value into its byte representation.
 * 
 * @param longValue
 *            value The long value to transform.
 * @return The byte representation of the given value.
 */
public static byte[] long2VarIntByteArray(long longValue) {
	try {
		long value = longValue;

		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
		DataOutput out = new DataOutputStream(byteArrayOutputStream);

		while ((value & 0xFFFFFFFFFFFFFF80L) != 0L) {
			out.writeByte(((int) value & 0x7F) | 0x80);
			value >>>= 7;
		}

		out.writeByte((int) value & 0x7F);

		return byteArrayOutputStream.toByteArray();
	} catch (IOException e) {
		LOG.error("Could not transform the given long value into its VarInt representation - "
				+ "Using BitcoinJ as Fallback. This could cause problems for values > 127.", e);
		return (new VarInt(longValue)).encode();
	}
}
 
开发者ID:onixred,项目名称:golos4j,代码行数:29,代码来源:Util.java

示例6: saveVarMapping

import java.io.DataOutputStream; //导入依赖的package包/类
private void saveVarMapping(VariableNumber var, ZipOutputStream zos) throws IOException {
	//System.out.println("VAR "+ filepath + var.getName()+"_Map"+BINext);

	zos.putNextEntry(new ZipEntry(var.getName() + "_Map" + BINext));
	DataOutputStream dos = new DataOutputStream(zos);

	Mapping[] map = var.getMapping().getMappingValue();

	dos.write(map.length);
	for (Mapping element : map) {
		dos.writeDouble(element.getConversion());
		dos.writeUTF(element.getValue().toString());
	}
	dos.flush();
	zos.closeEntry();

}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:18,代码来源:JwatSession.java

示例7: execShellCmd

import java.io.DataOutputStream; //导入依赖的package包/类
/**
     * 执行shell命令
     *
     * @param cmd
     */
//    http://blog.csdn.net/mad1989/article/details/38109689/
    public void execShellCmd(String cmd) {
        L.d("执行命令 " + cmd);
        try {
            // 申请获取root权限,这一步很重要,不然会没有作用
            Process process = Runtime.getRuntime().exec("su");
            // 获取输出流
            OutputStream outputStream = process.getOutputStream();
            DataOutputStream dataOutputStream = new DataOutputStream(
                    outputStream);
            dataOutputStream.writeBytes(cmd);
            dataOutputStream.flush();
            dataOutputStream.close();
            outputStream.close();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
 
开发者ID:kaixuanluo,项目名称:pc-android-controller-android,代码行数:24,代码来源:Utils.java

示例8: excuteCBASQuery

import java.io.DataOutputStream; //导入依赖的package包/类
private String excuteCBASQuery(String query) throws Exception {
    URL url = new URL(getCbasURL());
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");

    connection.setRequestProperty("Content-Type",
            "application/x-www-form-urlencoded");
    connection.setRequestProperty("ignore-401",
            "true");

    String encodedQuery = URLEncoder.encode(query, "UTF-8");
    String payload = "statement=" + encodedQuery;

    DataOutputStream out = new DataOutputStream(connection.getOutputStream());
    out.writeBytes(payload);
    out.flush();
    out.close();

    int responseCode = connection.getResponseCode();

    BufferedReader in = new BufferedReader(
            new InputStreamReader(connection.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();
    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();

    return response.toString();
}
 
开发者ID:couchbaselabs,项目名称:GitTalent,代码行数:34,代码来源:AnalyticsController.java

示例9: testLongArray

import java.io.DataOutputStream; //导入依赖的package包/类
/**
 * Tests data serializing a <code>long</code> array
 */
@Test
public void testLongArray() throws Exception {
  long[] array = new long[] {4, 5, 6};

  DataOutputStream out = getDataOutput();
  DataSerializer.writeLongArray(array, out);
  out.flush();

  DataInput in = getDataInput();
  long[] array2 = DataSerializer.readLongArray(in);

  assertEquals(array.length, array2.length);
  for (int i = 0; i < array.length; i++) {
    assertEquals(array[i], array2[i]);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:20,代码来源:DataSerializableJUnitTest.java

示例10: testWideWritable2

import java.io.DataOutputStream; //导入依赖的package包/类
public void testWideWritable2() throws Exception {
  Writable[] manyWrits = makeRandomWritables(71);
  
  TupleWritable sTuple = new TupleWritable(manyWrits);
  for (int i =0; i<manyWrits.length; i++)
  {
    sTuple.setWritten(i);
  }
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  sTuple.write(new DataOutputStream(out));
  ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
  TupleWritable dTuple = new TupleWritable();
  dTuple.readFields(new DataInputStream(in));
  assertTrue("Failed to write/read tuple", sTuple.equals(dTuple));
  assertEquals("All tuple data has not been read from the stream", 
    -1, in.read());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:TestJoinTupleWritable.java

示例11: sendPlayerToServer

import java.io.DataOutputStream; //导入依赖的package包/类
public ListenableFuture<?> sendPlayerToServer(Player player, @Nullable String bungeeName, boolean quiet) {
    if(localServer.bungee_name().equals(bungeeName) || (localServer.role() == ServerDoc.Role.LOBBY && bungeeName == null)) {
        return Futures.immediateFuture(null);
    }

    final ByteArrayOutputStream message = new ByteArrayOutputStream();
    final DataOutputStream out = new DataOutputStream(message);

    try {
        out.writeUTF(quiet ? "ConnectQuiet" : "Connect");
        out.writeUTF(bungeeName == null ? "default" : bungeeName);
    } catch(IOException e) {
        return Futures.immediateFailedFuture(e);
    }

    player.sendPluginMessage(plugin, PLUGIN_CHANNEL, message.toByteArray());
    return quitFuture(player);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:19,代码来源:PlayerServerChanger.java

示例12: getClientExtensions

import java.io.DataOutputStream; //导入依赖的package包/类
@Override
public Hashtable<Integer, byte[]> getClientExtensions() throws IOException {
    Hashtable<Integer, byte[]> clientExtensions = super.getClientExtensions();
    if (clientExtensions == null) {
        clientExtensions = new Hashtable<Integer, byte[]>();
    }

    //Add host_name
    byte[] host_name = host.getBytes();

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final DataOutputStream dos = new DataOutputStream(baos);
    dos.writeShort(host_name.length + 3); // entry size
    dos.writeByte(0); // name type = hostname
    dos.writeShort(host_name.length);
    dos.write(host_name);
    dos.close();
    clientExtensions.put(ExtensionType.server_name, baos.toByteArray());
    return clientExtensions;
}
 
开发者ID:tobszarny,项目名称:ssl-provider-jvm16,代码行数:21,代码来源:BouncyCastleDefaultTlsClient.java

示例13: tryArrayList

import java.io.DataOutputStream; //导入依赖的package包/类
private void tryArrayList(int size) throws IOException, ClassNotFoundException {
  setUp();
  final Random random = getRandom();
  final ArrayList list = size == -1 ? null : new ArrayList(size);
  for (int i = 0; i < size; i++) {
    list.add(new Long(random.nextLong()));
  }

  DataOutputStream out = getDataOutput();
  DataSerializer.writeArrayList(list, out);
  out.flush();

  DataInput in = getDataInput();
  ArrayList list2 = DataSerializer.readArrayList(in);
  assertEquals(list, list2);
  tearDown();
}
 
开发者ID:ampool,项目名称:monarch,代码行数:18,代码来源:DataSerializableJUnitTest.java

示例14: testSerialize

import java.io.DataOutputStream; //导入依赖的package包/类
/**
 * Assert that MKeyBase can be serialized and de-serialized as expected.
 *
 * @throws IOException
 * @throws ClassNotFoundException
 */
@Test
public void testSerialize() throws IOException, ClassNotFoundException {
  final MKeyBase key = new MKeyBase("abc".getBytes());
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  DataOutputStream dos = new DataOutputStream(bos);

  key.toData(dos);

  DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
  final MKeyBase readKey = new MKeyBase();
  readKey.fromData(dis);

  dis.close();
  dos.close();
  bos.close();

  /** assert that two objects are different but are same for equals and compareTo **/
  assertFalse(key == readKey);
  assertEquals(key, readKey);
  assertTrue(key.equals(readKey));
  assertEquals(key.hashCode(), readKey.hashCode());
  assertEquals(0, key.compareTo(key));
}
 
开发者ID:ampool,项目名称:monarch,代码行数:30,代码来源:MKeyBaseTest.java

示例15: serializeHeader

import java.io.DataOutputStream; //导入依赖的package包/类
/**
 * Serialize a trie2 Header and Index onto an OutputStream.  This is
 * common code used for  both the Trie2_16 and Trie2_32 serialize functions.
 * @param dos the stream to which the serialized Trie2 data will be written.
 * @return the number of bytes written.
 */
protected int serializeHeader(DataOutputStream dos) throws IOException {
    // Write the header.  It is already set and ready to use, having been
    //  created when the Trie2 was unserialized or when it was frozen.
    int  bytesWritten = 0;

    dos.writeInt(header.signature);
    dos.writeShort(header.options);
    dos.writeShort(header.indexLength);
    dos.writeShort(header.shiftedDataLength);
    dos.writeShort(header.index2NullOffset);
    dos.writeShort(header.dataNullOffset);
    dos.writeShort(header.shiftedHighStart);
    bytesWritten += 16;

    // Write the index
    int i;
    for (i=0; i< header.indexLength; i++) {
        dos.writeChar(index[i]);
    }
    bytesWritten += header.indexLength;
    return bytesWritten;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:29,代码来源:Trie2.java


注:本文中的java.io.DataOutputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。