List of usage examples for java.io ObjectOutputStream flush
public void flush() throws IOException
From source file:org.echocat.nodoodle.transport.HandlerPacker.java
protected void writeData(Handler<?> handler, JarOutputStream jar, String dataFileName) throws IOException { if (handler == null) { throw new NullPointerException(); }/* w w w . j av a2 s .co m*/ if (jar == null) { throw new NullPointerException(); } final JarEntry entry = new JarEntry(dataFileName); jar.putNextEntry(entry); final ObjectOutputStream oos = new ObjectOutputStream(jar); oos.writeObject(handler); oos.flush(); jar.closeEntry(); }
From source file:org.apache.storm.hdfs.security.AutoHDFSNimbus.java
@SuppressWarnings("unchecked") private byte[] getHadoopCredentials(Map conf, final Configuration configuration, final String topologySubmitterUser) { try {/*from w w w. j av a2 s. com*/ if (UserGroupInformation.isSecurityEnabled()) { login(configuration); final URI nameNodeURI = conf.containsKey(TOPOLOGY_HDFS_URI) ? new URI(conf.get(TOPOLOGY_HDFS_URI).toString()) : FileSystem.getDefaultUri(configuration); UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); final UserGroupInformation proxyUser = UserGroupInformation.createProxyUser(topologySubmitterUser, ugi); Credentials creds = (Credentials) proxyUser.doAs(new PrivilegedAction<Object>() { @Override public Object run() { try { FileSystem fileSystem = FileSystem.get(nameNodeURI, configuration); Credentials credential = proxyUser.getCredentials(); if (configuration.get(STORM_USER_NAME_KEY) == null) { configuration.set(STORM_USER_NAME_KEY, hdfsPrincipal); } fileSystem.addDelegationTokens(configuration.get(STORM_USER_NAME_KEY), credential); LOG.info("Delegation tokens acquired for user {}", topologySubmitterUser); return credential; } catch (IOException e) { throw new RuntimeException(e); } } }); ByteArrayOutputStream bao = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bao); creds.write(out); out.flush(); out.close(); return bao.toByteArray(); } else { throw new RuntimeException("Security is not enabled for HDFS"); } } catch (Exception ex) { throw new RuntimeException("Failed to get delegation tokens.", ex); } }
From source file:org.cloudcoder.app.loadtester.EditSequence.java
/** * Save to given file./*from w w w. j a v a 2 s . c o m*/ * * @param fileName name of file * @throws IOException */ public void saveToFile(String fileName) throws IOException { ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(new FileOutputStream(fileName)); oos.writeObject(this); oos.flush(); } finally { IOUtils.closeQuietly(oos); } }
From source file:org.springframework.cloud.aws.messaging.support.converter.ObjectMessageConverter.java
@Override public Object convertToInternal(Object payload, MessageHeaders headers) { if (!(payload instanceof Serializable)) { throw new IllegalArgumentException("Can't convert payload, it must be of type Serializable"); }//from www . ja va 2s. co m ByteArrayOutputStream content = new ByteArrayOutputStream(); Base64OutputStream base64OutputStream = new Base64OutputStream(content, true, 0, null); ObjectOutputStream objectOutputStream = null; try { objectOutputStream = new ObjectOutputStream(base64OutputStream); objectOutputStream.writeObject(payload); objectOutputStream.flush(); } catch (IOException e) { throw new MessageConversionException("Error converting payload into binary representation", e); } finally { if (objectOutputStream != null) { try { objectOutputStream.close(); } catch (IOException e) { LOGGER.warn("Error closing object output stream while writing message payload", e); } } } return new String(content.toByteArray(), 0, content.size(), this.encoding); }
From source file:com.joliciel.talismane.parser.ParsingConstrainerImpl.java
@Override public void onCompleteParse() { if (this.transitionSystem == null) this.transitionSystem = TalismaneSession.getTransitionSystem(); if (this.file != null) { try {// w w w. jav a2 s .c o m ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file, false)); zos.putNextEntry(new ZipEntry("ParsingConstrainer.obj")); ObjectOutputStream oos = new ObjectOutputStream(zos); try { oos.writeObject(this); } finally { oos.flush(); } zos.flush(); zos.close(); } catch (IOException ioe) { LogUtils.logError(LOG, ioe); throw new RuntimeException(ioe); } } }
From source file:com.nextcloud.android.sso.InputStreamBinder.java
private <T extends Serializable> ByteArrayInputStream serializeObjectToInputStream(T obj) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(obj);//w w w. ja va2 s. c o m oos.flush(); oos.close(); return new ByteArrayInputStream(baos.toByteArray()); }
From source file:disko.flow.analyzers.socket.SocketTransmitter.java
public void writeMessage(Message message) { log.debug("Establishing connection to " + host + ":" + port); while (true) { Socket socket = null;//from w ww. j av a 2 s. c o m ObjectOutputStream out = null; try { socket = new Socket(host, port); out = new ObjectOutputStream(socket.getOutputStream()); out.writeObject(message); out.flush(); log.debug("Sent " + message); return; } catch (UnknownHostException e) { log.error("Error connecting to " + host + ":" + port, e); } catch (IOException e) { log.error("Error sending to " + host + ":" + port + " message " + message.getData(), e); } finally { if (out != null) try { out.close(); } catch (Throwable ignored) { log.error("While closing transmitter output.", ignored); } if (socket != null) try { socket.close(); } catch (Throwable ignored) { log.error("While closing transmitter socket.", ignored); } } try { Thread.sleep(1000); } catch (InterruptedException ignored) { break; } } }
From source file:ByteFIFOTest.java
private void makeSrcData() throws IOException { String[] list = { "The first string is right here", "The second string is a bit longer and also right here", "The third string", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "0123456789", "The last string in the list" }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(list);/*w w w . j a v a 2s. com*/ oos.flush(); oos.close(); srcData = baos.toByteArray(); }
From source file:edu.vt.middleware.gator.log4j.SocketServerTest.java
/** * Tests connecting to the socket server and sending a logging event that * should be written to configured appenders. * * @throws Exception On errors.// w w w . j a va2 s . c o m */ @Test public void testConnectAndLog() throws Exception { final Socket sock = new Socket(); try { final SocketAddress addr = new InetSocketAddress(InetAddress.getByName(server.getBindAddress()), server.getPort()); sock.connect(addr, SOCKET_CONNECT_TIMEOUT); // Allow the socket server time to build the hierarchy // before sending a test logging event Thread.sleep(2000); Assert.assertEquals(1, server.getLoggingEventHandlers().size()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Sending test logging event."); } final LoggingEvent event = new LoggingEvent(TEST_CATEGORY, Logger.getLogger(TEST_CATEGORY), Level.DEBUG, TEST_MESSAGE, null); final ObjectOutputStream oos = new ObjectOutputStream(sock.getOutputStream()); oos.writeObject(event); oos.flush(); } finally { if (sock.isConnected()) { sock.close(); } } // Pause to allow time for logging events to be written Thread.sleep(2000); // Client socket close should trigger cleanup of server handler mapping Assert.assertEquals(0, server.getLoggingEventHandlers().size()); for (AppenderConfig appender : testProject.getAppenders()) { final String logFilePath = FileHelper.pathCat(CLIENT_ROOT_DIR, testProject.getName(), appender.getAppenderParam("file").getValue()); final String contents = readTextFile(logFilePath); Assert.assertTrue(contents.contains(TEST_MESSAGE)); } }
From source file:com.openteach.diamond.network.waverider.master.MasterState.java
public ByteBuffer toByteBuffer() { ByteArrayOutputStream bout = null; ObjectOutputStream oout = null; try {/*from www. j ava 2 s . com*/ bout = new ByteArrayOutputStream(); oout = new ObjectOutputStream(bout); oout.writeObject(this); oout.flush(); return ByteBuffer.wrap(bout.toByteArray()); } catch (IOException e) { throw new RuntimeException(e); } finally { try { if (oout != null) { oout.close(); } if (bout != null) { bout.close(); } } catch (IOException e) { logger.error(e); } } }