Code example for ObjectOutputStream

Methods: close, flush, writeInt, writeLong, writeObject

0
	public synchronized void saveToCache() throws CacheFailureException 
	{ 
		try 
		{ 
			ObjectOutputStream output = 
				new ObjectOutputStream(
						new QuietBufferedOutputStream( 
								new FileOutputStream(fullFilename())));
			//first object is the query result 
			output.writeObject(qr);
			//next is a int saying what list item should be read next 
			output.writeInt(nextElementPos);
			//next is a timestamp 
			if (timestamp == null)
			{	 
				Time t = new Time();
				t.setToNow();
				output.writeLong(t.toMillis(false));
				this.timestamp = t;
			} 
			else 
			{ 
				output.writeLong(timestamp.toMillis(false));
			} 
			output.flush();
			output.close();
		} 
		catch(Exception e)
		{ 
			throw new CacheFailureException("Line 283", e);
		}