Java Code Examples for java.io.ObjectOutputStream.flush()

The following are Jave code examples for showing how to use flush() of the java.io.ObjectOutputStream class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: T0rlib4j   File: TorClientSocks4.java   View Source Code Vote up 6 votes
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();
}
 
Example 2
Project: datatree   File: TreeTest.java   View Source Code Vote up 6 votes
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);
	}
 
Example 3
Project: T0rlib4Android   File: TorClientSocks4.java   View Source Code Vote up 6 votes
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();
}
 
Example 4
Project: openjdk-jdk10   File: Doubles.java   View Source Code Vote up 6 votes
/**
 * 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();
        }
    }
}
 
Example 5
Project: jaffa-framework   File: EncryptionHelper.java   View Source Code Vote up 6 votes
/** 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!!");
    }
}
 
Example 6
Project: letv   File: FileUtils.java   View Source Code Vote up 6 votes
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();
        }
    }
}
 
Example 7
Project: jdk8u-jdk   File: GetPutFieldTrees.java   View Source Code Vote up 6 votes
/**
 * 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();
        }
    }
}
 
Example 8
Project: CrashCoin   File: WalletClient.java   View Source Code Vote up 6 votes
/**
 * 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");
}
 
Example 9
Project: MARF-for-Android   File: TransitionTable.java   View Source Code Vote up 6 votes
/**
 * 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;
    }
}
 
Example 10
Project: openjdk-jdk10   File: Bytes.java   View Source Code Vote up 6 votes
/**
 * 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();
        }
    }
}
 
Example 11
Project: JAddOn   File: Client.java   View Source Code Vote up 6 votes
/**
 * 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;
    }
}
 
Example 12
Project: jrpip   File: ByteUtils.java   View Source Code Vote up 5 votes
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;
}
 
Example 13
Project: FuzzDroid   File: SocketServer.java   View Source Code Vote up 5 votes
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);
}
 
Example 14
Project: CrypDist   File: ResponsedMessageTask.java   View Source Code Vote up 5 votes
@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;
}
 
Example 15
Project: lighthouse   File: SerializableEntity.java   View Source Code Vote up 5 votes
@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();
    }
}
 
Example 16
Project: bridgechat   File: ThreadServer.java   View Source Code Vote up 5 votes
public void straightTransmit(Transmissible message, ObjectOutputStream out){
	try {
		out.writeObject(message);
		out.flush();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 17
Project: openjdk-jdk10   File: ServantManagerImpl.java   View Source Code Vote up 5 votes
private void writeCounter()
{
    try {
        counterFile.delete();
        FileOutputStream fos = new FileOutputStream(counterFile);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(counter);
        oos.flush();
        oos.close();

    } catch (Exception ex) {
    }
}
 
Example 18
Project: MyFlightbookAndroid   File: MFBUtil.java   View Source Code Vote up 5 votes
public static String serializeToString(Serializable o) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(o);
        oos.flush();
        return new String(Base64.encode(bos.toByteArray(), Base64.DEFAULT));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}
 
Example 19
Project: SuperiorCraft   File: SaveUtil.java   View Source Code Vote up 5 votes
public static void save() {
	try {
		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("players.data"));
		out.writeObject(playerData);
		out.flush();
		out.close();
	} catch (IOException e) {e.printStackTrace();}
}
 
Example 20
Project: incubator-netbeans   File: RemoteAgent.java   View Source Code Vote up 4 votes
private void handleLoadFailure(Throwable ex, ObjectOutputStream out) throws IOException {
    debug("*** Load failure: %s\n", ex);
    out.writeInt(RESULT_FAIL);
    out.writeUTF(ex.toString());
    out.flush();
}