Here you can find the source of deserializeSpecial(InputStream is, Class
Parameter | Description |
---|---|
is | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static <T> T deserializeSpecial(InputStream is, Class<T> clazz) throws IOException
//package com.java2s; /**/*from w w w .ja v a 2 s.c om*/ * Project: Platforms for Collaboration at the AMMRF * * Copyright (c) Intersect Pty Ltd, 2011 * * @see http://www.ammrf.org.au * @see http://www.intersect.org.au * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * This program contains open source third party libraries from a number of * sources, please read the THIRD_PARTY.txt file for more details. */ import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; public class Main { /** * Like deserialize but leaves the supplied stream open. * @param is * @return * @throws IOException */ public static <T> T deserializeSpecial(InputStream is, Class<T> clazz) throws IOException { Object obj = ""; try { ObjectInputStream ois = new ObjectInputStream(is); obj = ois.readObject(); return clazz.cast(obj); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (ClassCastException e) { throw new IOException("Expecting " + clazz.getName() + ", found " + obj.getClass()); } } }