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


Java ObjectOutputStream.flush方法代碼示例

本文整理匯總了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();
}
 
開發者ID:PanagiotisDrakatos,項目名稱:T0rlib4j,代碼行數:26,代碼來源:TorClientSocks4.java

示例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);
	}
 
開發者ID:berkesa,項目名稱:datatree,代碼行數:25,代碼來源:TreeTest.java

示例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();
}
 
開發者ID:PanagiotisDrakatos,項目名稱:T0rlib4Android,代碼行數:22,代碼來源:TorClientSocks4.java

示例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();
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:Doubles.java

示例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!!");
    }
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:38,代碼來源:EncryptionHelper.java

示例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();
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:18,代碼來源:FileUtils.java

示例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();
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:GetPutFieldTrees.java

示例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");
}
 
開發者ID:StanIsAdmin,項目名稱:CrashCoin,代碼行數:37,代碼來源:WalletClient.java

示例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;
    }
}
 
開發者ID:souhaib100,項目名稱:MARF-for-Android,代碼行數:28,代碼來源:TransitionTable.java

示例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();
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:Bytes.java

示例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;
    }
}
 
開發者ID:Panzer1119,項目名稱:JAddOn,代碼行數:21,代碼來源:Client.java

示例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;
}
 
開發者ID:goldmansachs,項目名稱:jrpip,代碼行數:28,代碼來源:ByteUtils.java

示例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);
}
 
開發者ID:srasthofer,項目名稱:FuzzDroid,代碼行數:8,代碼來源:SocketServer.java

示例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;
}
 
開發者ID:CrypDist,項目名稱:CrypDist,代碼行數:39,代碼來源:ResponsedMessageTask.java

示例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();
    }
}
 
開發者ID:kalikov,項目名稱:lighthouse,代碼行數:13,代碼來源:SerializableEntity.java


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