Code example for DataInputStream

Methods: close, readInt, readLong

0
        long savedFileSize = -1;
        long savedCrc = -1;
        int savedVersion = -1;
 
        // Extract the previous bookmark file size & CRC from the saved state 
        DataInputStream in = new DataInputStream(
                new FileInputStream(oldState.getFileDescriptor()));
        try { 
            savedFileSize = in.readLong();
            savedCrc = in.readLong();
            savedVersion = in.readInt();
        } catch (EOFException e) {
            // It means we had no previous state; that's fine 
            return; 
        } finally { 
            if (in != null) {
                in.close();
            } 
        } 
        // Write the existing state 
        writeBackupState(savedFileSize, savedCrc, newState);
    }