Search in sources :

Example 76 with ObjectInputStream

use of java.io.ObjectInputStream in project javatari by ppeccin.

the class CartridgeSavestate method getConsoleState.

public ConsoleState getConsoleState() {
    try {
        ByteArrayInputStream byteStream = new ByteArrayInputStream(rom.content);
        byteStream.skip(contentIdentifier.length);
        ObjectInputStream objStream = new ObjectInputStream(byteStream);
        return (ConsoleState) objStream.readObject();
    } catch (Exception ex) {
        // Cast or IO errors
        ex.printStackTrace();
        return null;
    }
}
Also used : ConsoleState(org.javatari.atari.console.savestate.ConsoleState) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 77 with ObjectInputStream

use of java.io.ObjectInputStream in project javatari by ppeccin.

the class RemoteReceiver method tryConnection.

private void tryConnection(String serverAddress) throws IOException, IllegalArgumentException {
    this.serverAddress = serverAddress;
    try {
        String addr = getHost(serverAddress);
        int port = getPort(serverAddress);
        socket = new Socket(addr, port);
        socket.setTcpNoDelay(true);
        socketOutputStream = socket.getOutputStream();
        outputStream = new ObjectOutputStream(socketOutputStream);
        socketInputStream = socket.getInputStream();
        inputStream = new ObjectInputStream(socketInputStream);
    } catch (IOException ex) {
        disconnection();
        throw ex;
    }
    resetUpdatesPending();
    updatesReceiver = new UpdatesReceiver();
    updatesReceiver.start();
    updatesConsumer = new UpdatesConsumer();
    updatesConsumer.start();
    console.connected();
    notifyConnectionStatusListeners();
}
Also used : IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) Socket(java.net.Socket) ObjectInputStream(java.io.ObjectInputStream)

Example 78 with ObjectInputStream

use of java.io.ObjectInputStream in project javatari by ppeccin.

the class RemoteTransmitter method connect.

private void connect(Socket toSocket) throws IOException {
    socket = toSocket;
    socket.setTcpNoDelay(true);
    socketOutputStream = socket.getOutputStream();
    outputStream = new ObjectOutputStream(socketOutputStream);
    socketInputStream = socket.getInputStream();
    inputStream = new ObjectInputStream(socketInputStream);
    resetUpdatesPending();
    console.clientConnected();
    notifyConnectionStatusListeners();
}
Also used : ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 79 with ObjectInputStream

use of java.io.ObjectInputStream in project flink by apache.

the class RocksDBKeyedStateBackend method restoreOldSavepointKeyedState.

/**
	 * For backwards compatibility, remove again later!
	 */
@Deprecated
private void restoreOldSavepointKeyedState(Collection<KeyGroupsStateHandle> restoreState) throws Exception {
    if (restoreState.isEmpty()) {
        return;
    }
    Preconditions.checkState(1 == restoreState.size(), "Only one element expected here.");
    HashMap<String, RocksDBStateBackend.FinalFullyAsyncSnapshot> namedStates;
    try (FSDataInputStream inputStream = restoreState.iterator().next().openInputStream()) {
        namedStates = InstantiationUtil.deserializeObject(inputStream, userCodeClassLoader);
    }
    Preconditions.checkState(1 == namedStates.size(), "Only one element expected here.");
    DataInputView inputView = namedStates.values().iterator().next().stateHandle.getState(userCodeClassLoader);
    // clear k/v state information before filling it
    kvStateInformation.clear();
    // first get the column family mapping
    int numColumns = inputView.readInt();
    Map<Byte, StateDescriptor<?, ?>> columnFamilyMapping = new HashMap<>(numColumns);
    for (int i = 0; i < numColumns; i++) {
        byte mappingByte = inputView.readByte();
        ObjectInputStream ooIn = new InstantiationUtil.ClassLoaderObjectInputStream(new DataInputViewStream(inputView), userCodeClassLoader);
        StateDescriptor stateDescriptor = (StateDescriptor) ooIn.readObject();
        columnFamilyMapping.put(mappingByte, stateDescriptor);
        // this will fill in the k/v state information
        getColumnFamily(stateDescriptor, MigrationNamespaceSerializerProxy.INSTANCE);
    }
    // try and read until EOF
    try {
        // the EOFException will get us out of this...
        while (true) {
            byte mappingByte = inputView.readByte();
            ColumnFamilyHandle handle = getColumnFamily(columnFamilyMapping.get(mappingByte), MigrationNamespaceSerializerProxy.INSTANCE);
            byte[] keyAndNamespace = BytePrimitiveArraySerializer.INSTANCE.deserialize(inputView);
            ByteArrayInputStreamWithPos bis = new ByteArrayInputStreamWithPos(keyAndNamespace);
            K reconstructedKey = keySerializer.deserialize(new DataInputViewStreamWrapper(bis));
            int len = bis.getPosition();
            int keyGroup = (byte) KeyGroupRangeAssignment.assignToKeyGroup(reconstructedKey, numberOfKeyGroups);
            if (keyGroupPrefixBytes == 1) {
                // copy and override one byte (42) between key and namespace
                System.arraycopy(keyAndNamespace, 0, keyAndNamespace, 1, len);
                keyAndNamespace[0] = (byte) keyGroup;
            } else {
                byte[] largerKey = new byte[1 + keyAndNamespace.length];
                // write key-group
                largerKey[0] = (byte) ((keyGroup >> 8) & 0xFF);
                largerKey[1] = (byte) (keyGroup & 0xFF);
                // write key
                System.arraycopy(keyAndNamespace, 0, largerKey, 2, len);
                //skip one byte (42), write namespace
                System.arraycopy(keyAndNamespace, 1 + len, largerKey, 2 + len, keyAndNamespace.length - len - 1);
                keyAndNamespace = largerKey;
            }
            byte[] value = BytePrimitiveArraySerializer.INSTANCE.deserialize(inputView);
            db.put(handle, keyAndNamespace, value);
        }
    } catch (EOFException e) {
    // expected
    }
}
Also used : HashMap(java.util.HashMap) DataInputView(org.apache.flink.core.memory.DataInputView) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) ByteArrayInputStreamWithPos(org.apache.flink.core.memory.ByteArrayInputStreamWithPos) ReducingStateDescriptor(org.apache.flink.api.common.state.ReducingStateDescriptor) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) AggregatingStateDescriptor(org.apache.flink.api.common.state.AggregatingStateDescriptor) StateDescriptor(org.apache.flink.api.common.state.StateDescriptor) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) FoldingStateDescriptor(org.apache.flink.api.common.state.FoldingStateDescriptor) EOFException(java.io.EOFException) FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) DataInputViewStream(org.apache.flink.api.java.typeutils.runtime.DataInputViewStream) ObjectInputStream(java.io.ObjectInputStream)

Example 80 with ObjectInputStream

use of java.io.ObjectInputStream in project flink by apache.

the class DelimitedInputFormatTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    final byte[] DELIMITER = new byte[] { 1, 2, 3, 4 };
    final int NUM_LINE_SAMPLES = 7;
    final int LINE_LENGTH_LIMIT = 12345;
    final int BUFFER_SIZE = 178;
    DelimitedInputFormat<String> format = new MyTextInputFormat();
    format.setDelimiter(DELIMITER);
    format.setNumLineSamples(NUM_LINE_SAMPLES);
    format.setLineLengthLimit(LINE_LENGTH_LIMIT);
    format.setBufferSize(BUFFER_SIZE);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(format);
    oos.flush();
    oos.close();
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    @SuppressWarnings("unchecked") DelimitedInputFormat<String> deserialized = (DelimitedInputFormat<String>) ois.readObject();
    assertEquals(NUM_LINE_SAMPLES, deserialized.getNumLineSamples());
    assertEquals(LINE_LENGTH_LIMIT, deserialized.getLineLengthLimit());
    assertEquals(BUFFER_SIZE, deserialized.getBufferSize());
    assertArrayEquals(DELIMITER, deserialized.getDelimiter());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Aggregations

ObjectInputStream (java.io.ObjectInputStream)1041 ByteArrayInputStream (java.io.ByteArrayInputStream)667 ObjectOutputStream (java.io.ObjectOutputStream)427 ByteArrayOutputStream (java.io.ByteArrayOutputStream)354 IOException (java.io.IOException)341 FileInputStream (java.io.FileInputStream)152 Test (org.junit.Test)128 File (java.io.File)89 InputStream (java.io.InputStream)85 BufferedInputStream (java.io.BufferedInputStream)47 Serializable (java.io.Serializable)40 HashMap (java.util.HashMap)35 ArrayList (java.util.ArrayList)31 FileNotFoundException (java.io.FileNotFoundException)27 FileOutputStream (java.io.FileOutputStream)27 Test (org.testng.annotations.Test)26 Map (java.util.Map)25 EOFException (java.io.EOFException)21 GZIPInputStream (java.util.zip.GZIPInputStream)21 ObjectInput (java.io.ObjectInput)20