/** * {@inheritDoc} */ @Override public void close() throws IOException { this.out.close(); } }
@Override public void close() throws IOException { out.close(); }
@Override public void close() throws IOException { out.close(); }
/** * 保存模型 */ public void saveModel(String filePath) throws IOException { ObjectOutput oot = new ObjectOutputStream(new FileOutputStream(filePath)); oot.writeObject(this); oot.flush(); oot.close(); }
public static byte[] serialize( Serializable object, ClassLoader classLoader ) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ObjectOutput out = null; byte[] result; try { out = new ObjectOutputStream(outputStream); out.writeObject(object); result = outputStream.toByteArray(); } finally { try { if( out != null ) { out.close(); } } catch( IOException ex ) { // ignore close exception } try { outputStream.close(); } catch( IOException ex ) { // ignore close exception } } return result; }
static String write(Serializable s) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = null; try { out = new ObjectOutputStream(bos); out.writeObject(s); return StringUtils.newStringUtf8(Base64.encodeBase64(bos.toByteArray(), false)); } finally { out.close(); bos.close(); } } catch( Exception ex ) { throw Log.errRTExcept(ex); } }
private void saveTimeStampCache(FileTimeStampChecker fileStampCheck) { try { File file = getSerializationTmpFile(); ObjectOutput out = new ObjectOutputStream( new FileOutputStream( file ) ); out.writeObject( fileStampCheck ); out.close(); context.logMessage( Diagnostic.Kind.OTHER, "Serialized " + fileStampCheck + " into " + file.getAbsolutePath() ); } catch (IOException e) { // ignore - if the serialization failed we just have to keep parsing the xml context.logMessage( Diagnostic.Kind.OTHER, "Error serializing " + fileStampCheck ); } }
public static void main(String[] args) throws Exception { LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog"); File file = new File("cookie.file"); ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); Set<Cookie> cookies = (Set<Cookie>) in.readObject(); in.close(); WebClient wc = new WebClient(); Iterator<Cookie> i = cookies.iterator(); while (i.hasNext()) { wc.getCookieManager().addCookie(i.next()); } HtmlPage p = wc.getPage("http://google.com"); ObjectOutput out = new ObjectOutputStream(new FileOutputStream("cookie.file")); out.writeObject(wc.getCookieManager().getCookies()); out.close(); }
/** * 序列化dat对象 */ public void save(final String path) throws IOException { ObjectOutput writer = null; try { writer = new ObjectOutputStream(new FileOutputStream(path)); writer.writeInt(datArrLen()); writer.writeInt(datItemSize()); for (Item item : dat) { if (item == null) { continue; } writer.writeObject(item); } } finally { if (writer != null) { writer.flush(); writer.close(); } } }
/** * @return Array. */ private byte[] serialize() { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); try { ObjectOutput out = new ObjectOutputStream(byteOut); out.writeObject(this); out.close(); } catch (IOException e) { Throwables.propagate(e); } return byteOut.toByteArray(); }
/** * @throws Exception If failed. */ @Test public void testSerialization() throws Exception { Map<String, IgfsMode> pathModes = new HashMap<>(); pathModes.put("path1", PRIMARY); pathModes.put("path2", PROXY); IgfsAttributes attrs = new IgfsAttributes("testIgfsName", 513000, 888, "meta", "data", DUAL_SYNC, pathModes, true); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput os = new ObjectOutputStream(bos); os.writeObject(attrs); os.close(); IgfsAttributes deserializedAttrs = (IgfsAttributes)new ObjectInputStream( new ByteArrayInputStream(bos.toByteArray())).readObject(); assertTrue(eq(attrs, deserializedAttrs)); }
output.close();
try { if (out != null) { out.close();
@SuppressWarnings("unchecked") @Test public void testSerialization() throws IOException, ClassNotFoundException { StreamSummary<String> vs = new StreamSummary<String>(3); String[] stream = {"X", "X", "Y", "Z", "A", "B", "C", "X", "X", "A", "C", "A", "A"}; for (String i : stream) { vs.offer(i); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutput oo = new ObjectOutputStream(baos); oo.writeObject(vs); oo.close(); ObjectInput oi = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); StreamSummary<String> clone = (StreamSummary<String>) oi.readObject(); assertEquals(vs.toString(), clone.toString()); }
output.close();
output.close(); Boolean usegz = channel.getUrl().getBooleanParameter(URLParamType.usegz.getName(), URLParamType.usegz.getBooleanValue()); int minGzSize = channel.getUrl().getIntParameter(URLParamType.mingzSize.getName(), URLParamType.mingzSize.getIntValue());
@SuppressWarnings("unchecked") @Test public void testCounterSerialization() throws IOException, ClassNotFoundException { StreamSummary<String> vs = new StreamSummary<String>(3); String[] stream = {"X", "X", "Y", "Z", "A", "B", "C", "X", "X", "A", "C", "A", "A"}; for (String i : stream) { vs.offer(i); } List<Counter<String>> topK = vs.topK(3); for (Counter<String> c : topK) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutput oo = new ObjectOutputStream(baos); oo.writeObject(c); oo.close(); ObjectInput oi = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); Counter<String> clone = (Counter<String>) oi.readObject(); assertEquals(c.getCount(), clone.getCount()); assertEquals(c.getError(), clone.getError()); assertEquals(c.getItem(), clone.getItem()); } }
output.close(); Boolean usegz = channel.getUrl().getBooleanParameter(URLParamType.usegz.getName(), URLParamType.usegz.getBooleanValue()); int minGzSize = channel.getUrl().getIntParameter(URLParamType.mingzSize.getName(), URLParamType.mingzSize.getIntValue());
private static byte[] marshal(Object obj) throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(bytes); out.writeObject(obj); out.flush(); out.close(); return bytes.toByteArray(); }
private static byte[] serialize(Object obj) throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutput out = new DroolsObjectOutputStream(bytes); out.writeObject(obj); out.flush(); out.close(); return bytes.toByteArray(); }