Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
public class BlackBox implements Serializable { private long altitude; private double speed; private float engineTemperature; private static final long serialVersionUID = 1L; public BlackBox(long altitude, double speed, float engineTemperature) { this.altitude = altitude; this.speed = speed; this.engineTemperature = engineTemperature; } // Saving the state of the object as a byte stream public byte[] getState() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = null; byte[] memento = null; try { out = new ObjectOutputStream(bos); out.writeObject(this); out.flush(); memento = bos.toByteArray(); } finally { try { bos.close(); } catch (IOException ex) { // ignore close exception } } return memento; } // Restoring state from memento public BlackBox setState(byte[] memento) throws Exception { ByteInputStream bis = new ByteInputStream(memento, memento.length); ObjectInputStream objectInputStream = new ObjectInputStream(bis); BlackBox blackBox = (BlackBox) objectInputStream.readObject(); objectInputStream.close(); return blackBox; } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)