本文整理汇总了Java中java.io.ObjectOutputStream.flush方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectOutputStream.flush方法的具体用法?Java ObjectOutputStream.flush怎么用?Java ObjectOutputStream.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.ObjectOutputStream
的用法示例。
在下文中一共展示了ObjectOutputStream.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
String fileStorageLocation = "torfiles";
OnionProxyManager onionProxyManager = new JavaOnionProxyManager(
new JavaOnionProxyContext(new File(fileStorageLocation)));
int totalSecondsPerTorStartup = 4 * 60;
int totalTriesPerTorStartup = 5;
// Start the Tor Onion Proxy
if (onionProxyManager.startWithRepeat(totalSecondsPerTorStartup, totalTriesPerTorStartup) == false) {
return;
}
// Start a hidden service listener
int hiddenServicePort = 80;
int localPort = onionProxyManager.getIPv4LocalHostSocksPort();
String OnionAdress = "d2lz63pgzqms2xxp.onion";
Socket clientSocket = Utilities.socks4aSocketConnection(OnionAdress, hiddenServicePort, "127.0.0.1", localPort);
ObjectOutputStream out = new ObjectOutputStream(clientSocket.getOutputStream());
out.flush();
out.writeObject("helloooooooooooooooooooooooo frommmmmmm hereeeeeeeeeeeeeeeeeeeeeeeeeeee");
out.flush();
}
示例2: testSerializationAndCloning
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
private final void testSerializationAndCloning(Tree node) throws Exception {
// Serialize
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(node);
oos.flush();
byte[] bytes = baos.toByteArray();
// System.out.println(new String(bytes));
// Deserialize
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
Tree copy = (Tree) ois.readObject();
String txtOriginal = node.toString("debug");
String txtCopy = copy.toString("debug");
assertEquals(txtOriginal, txtCopy);
// Cloning
txtCopy = node.clone().toString("debug");
assertEquals(txtOriginal, txtCopy);
}
示例3: Init
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public void Init() throws IOException, InterruptedException {
if(ctx==null){
Log.e("TorTest", "Couldn't start Tor!");
return;
}
String fileLocation = "torfiles";
// Start the Tor Onion Proxy
AndroidTorRelay node = new AndroidTorRelay(ctx,fileLocation);
int hiddenServicePort = 80;
int localPort = node.getSocksPort();
String OnionAdress = "xl5rbgygp2wbgdbn.onion";
String localhost="127.0.0.1";
Socket clientSocket = Utilities.socks4aSocketConnection(OnionAdress, hiddenServicePort, "127.0.0.1", localPort);
ObjectOutputStream out = new ObjectOutputStream(clientSocket.getOutputStream());
out.flush();
out.writeObject("i am workingg");
out.flush();
}
示例4: doReps
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, int nbatches, int ncycles)
throws Exception
{
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeDouble(0.0);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readDouble();
}
}
}
示例5: encryptObjectForURL
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/** Creates an encrypted and encode string from the source object.
* This string can be used directly in a URL without encoding.
* This assumes that the object passed in can be serialized.
* @param source The source Object to encrypt/encode
* @param key The secret key to use for encryption
* @throws NoSuchAlgorithmException May be thrown by the Cypher module
* @throws InvalidKeyException May be thrown by the Cypher module
* @throws NoSuchPaddingException May be thrown by the Cypher module
* @throws UnsupportedEncodingException May be thrown by the Cypher module
* @throws IllegalBlockSizeException May be thrown by the Cypher module
* @throws BadPaddingException May be thrown by the Cypher module
* @throws NotSerializableException if the source object is not Serializable
* @return The encoded/encrypted string
*/
public static String encryptObjectForURL(Object source, SecretKey key)
throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, javax.crypto.NoSuchPaddingException,
java.io.UnsupportedEncodingException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException,
java.io.NotSerializableException {
Cipher desCipher = Cipher.getInstance(ENCRYPT_POLICY);
desCipher.init(Cipher.ENCRYPT_MODE, key);
// Copy object to byte array
if(!(source instanceof Serializable))
throw new NotSerializableException();
try {
ByteArrayOutputStream b = new ByteArrayOutputStream();
ObjectOutputStream o = new ObjectOutputStream(b);
o.writeObject(source);
o.flush();
o.close();
return intoHexString( desCipher.doFinal( b.toByteArray() ) );
} catch (IOException e) {
throw new RuntimeException("No IO Exception should occur, this is all in-memory!!");
}
}
示例6: saveObjectToFile
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public static void saveObjectToFile(LetvBaseBean baseBean, String fileName) {
String path = getCachePath("");
if (!TextUtils.isEmpty(path)) {
try {
File file = new File(path + fileName);
file.createNewFile();
FileOutputStream fileOutputStream = new FileOutputStream(file);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(baseBean);
objectOutputStream.flush();
objectOutputStream.close();
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例7: doReps
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/**
* Run benchmark for given number of batches, with each batch containing
* the given number of cycles.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, Node[] trees, int nbatches)
throws Exception
{
int ncycles = trees.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(trees[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
示例8: writeWalletFile
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/**
* Methods used to write the current ClientWallent into a generated file.
* @param userPassword
* @param accountName
* @param keyPair
* @throws InvalidKeyException
* @throws InvalidParameterSpecException
* @throws IllegalBlockSizeException
* @throws BadPaddingException
* @throws FileNotFoundException
* @throws IOException
*/
public static void writeWalletFile(final char[] userPassword, final String accountName, final KeyPair keyPair)
throws InvalidKeyException,
InvalidParameterSpecException, IllegalBlockSizeException, BadPaddingException, FileNotFoundException,
IOException {
// Write wallet information in the wallet file
final WalletInformation walletInformation = Cryptography.walletInformationFromKeyPair(userPassword, keyPair);
// Creates wallet folder if not exists
final File walletFolder = new File(Parameters.WALLETS_PATH);
if (!walletFolder.exists()) {
walletFolder.mkdir();
}
// Creates new wallet file
final File f = new File(Parameters.WALLETS_PATH + accountName + ".wallet");
final ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
oos.writeObject(walletInformation);
oos.flush();
oos.close();
System.out.println("The creation of your wallet completed successfully");
System.out.println("Please sign in and start crashing coins");
}
示例9: save
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/**
* Saves current state of the TT (itself).
*
* @return <code>true</code> if serialization was successful
*/
public boolean save() {
try {
// Save to file
FileOutputStream oFOS = new FileOutputStream(this.strTableFile);
// Compressed
GZIPOutputStream oGZOS = new GZIPOutputStream(oFOS);
// Save objects
ObjectOutputStream oOOS = new ObjectOutputStream(oGZOS);
oOOS.writeObject(this);
oOOS.flush();
oOOS.close();
return true;
} catch (IOException e) {
System.err.println("TransitionTable::save() - WARNING: " + e.getMessage());
e.printStackTrace(System.err);
return false;
}
}
示例10: doReps
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, int nbatches, int ncycles)
throws Exception
{
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeByte(0);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readByte();
}
}
}
示例11: send
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/**
* Sends an object to the connected server
* @param object Object Object
* @return Boolean True if it worked, False if not
*/
public final boolean send(Object object) {
if(!connected && !isServerClient) {
StaticStandard.logErr("[CLIENT] Cannot send object, server is not connected");
return false;
}
try {
ObjectOutputStream oos = getObjectOutputStream();
oos.writeObject(object);
oos.flush();
return true;
} catch (Exception ex) {
//StaticStandard.logErr("[CLIENT] Error while sending: " + ex, ex); //TODO sieht heslig aus?
return false;
}
}
示例12: convertObjectToBytes
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public static byte[] convertObjectToBytes(Object data) throws IOException
{
byte[] pileOfBytes = null;
FixedDeflaterOutputStream zip = null;
try
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(200);
zip = new FixedDeflaterOutputStream(bos);
ObjectOutputStream oos = new ObjectOutputStream(zip);
oos.writeObject(data);
oos.flush();
bos.flush();
zip.finish();
zip.close();
zip = null;
pileOfBytes = bos.toByteArray();
bos.close();
}
finally
{
if (zip != null)
{
zip.finish();
}
}
return pileOfBytes;
}
示例13: sendResponse
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
private void sendResponse(ObjectOutputStream out, Object response)
throws IOException {
out.writeObject(response);
out.flush();
System.out.println("sending response to client-app...");
System.out.println(response);
}
示例14: call
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
@Override
public String call() throws Exception {
int trials = 0;
while(trials < Config.MESSAGE_MAX_TRIALS) {
try {
log.trace(p.getPeerServerPort());
log.trace(p.getAddress());
Socket messagedClient = new Socket(p.getAddress(), p.getPeerServerPort());
messagedClient.setSoTimeout(Config.MESSAGE_TIMEOUT);
ObjectOutputStream out = new ObjectOutputStream(messagedClient.getOutputStream());
out.writeInt(Config.MESSAGE_OUTGOING_RESPONSE);
out.writeUTF(msg);
out.flush();
ObjectInputStream in = new ObjectInputStream(new DataInputStream(messagedClient.getInputStream()));
int ack = in.readInt();
if (ack == Config.MESSAGE_ACK) {
String response = in.readUTF();
return response;
} else {
log.trace("Non flag read");
}
messagedClient.close();
} catch (IOException e) {
log.warn("EXCEPTIOON\n\n\n");
log.warn(e);
trials++;
continue;
}
trials++;
}
log.warn("Message cannot be sent after " + Config.MESSAGE_MAX_TRIALS + " trials");
log.warn(msg);
return null;
}
示例15: writeTo
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
@Override
public void writeTo(final OutputStream outstream) throws IOException {
ru.radiomayak.http.util.Args.notNull(outstream, "Output stream");
if (this.objSer == null) {
final ObjectOutputStream out = new ObjectOutputStream(outstream);
out.writeObject(this.objRef);
out.flush();
} else {
outstream.write(this.objSer);
outstream.flush();
}
}