Example usage for java.io StreamCorruptedException printStackTrace

List of usage examples for java.io StreamCorruptedException printStackTrace

Introduction

In this page you can find the example usage for java.io StreamCorruptedException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

public static Object ByteToObject(byte[] bytes) {
    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
    ObjectInput in = null;//from www . j  a  v a  2  s.com

    try {
        in = new ObjectInputStream(bis);
    } catch (StreamCorruptedException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Object obj = null;
    try {
        obj = in.readObject();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return obj;

}

From source file:Main.java

public static synchronized ArrayList<double[]> readArrayListFromFile(String filename) {
    ObjectInputStream input;/*from w  w  w.  ja va 2s .com*/
    ArrayList<double[]> x = null;
    try {
        input = new ObjectInputStream(new FileInputStream(new File(filename)));
        Object obj = input.readObject();
        if (obj != null)
            x = (ArrayList<double[]>) input.readObject();
        input.close();
        return x;
    } catch (StreamCorruptedException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    return x;
}

From source file:za.co.neilson.alarm.database.Database.java

public static Alarm getAlarm(int id) {
    // TODO Auto-generated method stub
    String[] columns = new String[] { COLUMN_ALARM_ID, COLUMN_ALARM_ACTIVE, COLUMN_ALARM_TIME,
            COLUMN_ALARM_DAYS, COLUMN_ALARM_DIFFICULTY, COLUMN_ALARM_TONE, COLUMN_ALARM_VIBRATE,
            COLUMN_ALARM_NAME };//from  ww  w .j av a2s  . c o  m
    Cursor c = getDatabase().query(ALARM_TABLE, columns, COLUMN_ALARM_ID + "=" + id, null, null, null, null);
    Alarm alarm = null;

    if (c.moveToFirst()) {

        alarm = new Alarm();
        alarm.setId(c.getInt(1));
        alarm.setAlarmActive(c.getInt(2) == 1);
        alarm.setAlarmTime(c.getString(3));
        byte[] repeatDaysBytes = c.getBlob(4);

        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(repeatDaysBytes);
        try {
            ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
            Alarm.Day[] repeatDays;
            Object object = objectInputStream.readObject();
            if (object instanceof Alarm.Day[]) {
                repeatDays = (Alarm.Day[]) object;
                alarm.setDays(repeatDays);
            }
        } catch (StreamCorruptedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        alarm.setDifficulty(Difficulty.values()[c.getInt(5)]);
        alarm.setAlarmTonePath(c.getString(6));
        alarm.setVibrate(c.getInt(7) == 1);
        alarm.setAlarmName(c.getString(8));
    }
    c.close();
    return alarm;
}

From source file:za.co.neilson.alarm.database.Database.java

public static List<Alarm> getAll() {
    List<Alarm> alarms = new ArrayList<Alarm>();
    Cursor cursor = Database.getCursor();
    if (cursor.moveToFirst()) {

        do {/*  w  w  w.  j  av a2 s  .com*/
            // COLUMN_ALARM_ID,
            // COLUMN_ALARM_ACTIVE,
            // COLUMN_ALARM_TIME,
            // COLUMN_ALARM_DAYS,
            // COLUMN_ALARM_DIFFICULTY,
            // COLUMN_ALARM_TONE,
            // COLUMN_ALARM_VIBRATE,
            // COLUMN_ALARM_NAME

            Alarm alarm = new Alarm();
            alarm.setId(cursor.getInt(0));
            alarm.setAlarmActive(cursor.getInt(1) == 1);
            alarm.setAlarmTime(cursor.getString(2));
            byte[] repeatDaysBytes = cursor.getBlob(3);

            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(repeatDaysBytes);
            try {
                ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
                Alarm.Day[] repeatDays;
                Object object = objectInputStream.readObject();
                if (object instanceof Alarm.Day[]) {
                    repeatDays = (Alarm.Day[]) object;
                    alarm.setDays(repeatDays);
                }
            } catch (StreamCorruptedException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }

            alarm.setDifficulty(Difficulty.values()[cursor.getInt(4)]);
            alarm.setAlarmTonePath(cursor.getString(5));
            alarm.setVibrate(cursor.getInt(6) == 1);
            alarm.setAlarmName(cursor.getString(7));

            alarms.add(alarm);

        } while (cursor.moveToNext());
    }
    cursor.close();
    return alarms;
}

From source file:node.Mailbox.java

/**
 * Accept a message from a socket. Adds the message to the appropriate queue
 *//*from   w ww.  ja  v  a  2s  . c  om*/
private void acceptMessage(Socket socket) {
    // get the source address
    String srcIP = socket.getInetAddress().getHostAddress();
    ObjectInputStream ois;
    try {
        InputStream is = socket.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);
        ois = new ObjectInputStream(bis);
        // now the Mailbox can block until it receives all message bytes
        // accept the message object
        AbstractMessage a = (AbstractMessage) ois.readObject();
        println("Received msg " + a.toString());
        // TODO MARK MESSAGE WITH OLD TIMESTAMP
        // save the srcIP for later. srcPort is already part of the message
        a.srcIP = srcIP;

        // cast to the appropriate message type
        if (a.msgType < MessageType.CONTROL) {
            // call the appropriate verifier, place the message in the queue
            // and call the appropriate message handler to reconstruct the
            // message over the network
            ControlMessage m = (ControlMessage) a;
            ctrlMsgsRecv.add(m);
        } else if (a.msgType < MessageType.EVOLVE) {
            EvolveMessage m = (EvolveMessage) a;
            evolveMsgsRecv.add(m);
        } else if (a.msgType < MessageType.DATA) {
            // TODO handle Data-specific messages (dataset/indexing
            // information, db webserver address, etc)
            throw new NoSuchMethodError("Handling DATA messages is not yet implemented");
        }
    } catch (StreamCorruptedException e) {
        println("Caught StreamCorruptedException: client must have terminated transmission", true);
    } catch (EOFException e) {
        println("Caught EOFException: client must have terminated transmission", true);
    } catch (IOException e) {
        log.log(Level.SEVERE, "Mailbox error: failed to accept message due to IOException", e);
        e.printStackTrace();
        log.severe(ExceptionUtils.getStackTrace(e));
    } catch (ClassNotFoundException e) {
        log.log(Level.SEVERE, "Mailbox error: failed to accept message due to ClassNotFoundException", e);
        e.printStackTrace();
        log.severe(ExceptionUtils.getStackTrace(e));
    }
}