List of usage examples for java.io ObjectOutputStream flush
public void flush() throws IOException
From source file:com.google.u2f.gaedemo.impl.DataStoreImpl.java
@Override public String storeSessionData(EnrollSessionData sessionData) { SecretKey key = new SecretKeySpec(SecretKeys.get().sessionEncryptionKey(), "AES"); byte[] ivBytes = new byte[16]; random.nextBytes(ivBytes);/*w w w . java 2s.co m*/ final IvParameterSpec IV = new IvParameterSpec(ivBytes); Cipher cipher; try { cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key, IV); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException e) { throw new RuntimeException(e); } SealedObject sealed; try { sealed = new SealedObject(sessionData, cipher); } catch (IllegalBlockSizeException | IOException e) { throw new RuntimeException(e); } ByteArrayOutputStream out; try { out = new ByteArrayOutputStream(); ObjectOutputStream outer = new ObjectOutputStream(out); outer.writeObject(sealed); outer.flush(); } catch (IOException e) { throw new RuntimeException(e); } return Base64.encodeBase64URLSafeString(out.toByteArray()); }
From source file:org.apache.jcs.auxiliary.lateral.socket.udp.LateralUDPSender.java
/** Description of the Method */ public void send(LateralElementDescriptor led) throws IOException { log.debug("sending LateralElementDescriptor"); try {/*ww w. ja va2s. c o m*/ final MyByteArrayOutputStream byteStream = new MyByteArrayOutputStream(); final ObjectOutputStream objectStream = new ObjectOutputStream(byteStream); objectStream.writeObject(led); objectStream.flush(); final byte[] bytes = byteStream.getBytes(); final DatagramPacket packet = new DatagramPacket(bytes, bytes.length, m_multicastAddress, m_multicastPort); m_localSocket.send(packet); } catch (IOException e) { log.error("Error sending message", e); throw e; } }
From source file:edu.umd.cs.buildServer.util.ServletAppender.java
@Override protected void append(LoggingEvent event) { if (!APPEND_TO_SUBMIT_SERVER) return;/* w w w .java 2 s. c o m*/ try { Throwable throwable = null; if (event.getThrowableInformation() != null) { String[] throwableStringRep = event.getThrowableStrRep(); StringBuffer stackTrace = new StringBuffer(); for (String stackTraceString : throwableStringRep) { stackTrace.append(stackTraceString); } throwable = new Throwable(stackTrace.toString()); } LoggingEvent newLoggingEvent = new LoggingEvent(event.getFQNOfLoggerClass(), event.getLogger(), event.getLevel(), getConfig().getHostname() + ": " + event.getMessage(), throwable); HttpClient client = new HttpClient(); client.setConnectionTimeout(HTTP_TIMEOUT); String logURL = config.getServletURL(SUBMIT_SERVER_HANDLEBUILDSERVERLOGMESSAGE_PATH); MultipartPostMethod post = new MultipartPostMethod(logURL); // add password ByteArrayOutputStream sink = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(sink); out.writeObject(newLoggingEvent); out.flush(); // add serialized logging event object post.addPart(new FilePart("event", new ByteArrayPartSource("event.out", sink.toByteArray()))); int status = client.executeMethod(post); if (status != HttpStatus.SC_OK) { throw new IOException("Couldn't contact server: " + status); } } catch (IOException e) { // TODO any way to log these without an infinite loop? System.err.println(e.getMessage()); e.printStackTrace(System.err); } }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.network.ServletReceiver.java
/** Send the given reponse to the client waiting for the given HttpServletResponse */ protected void respond(HttpServletResponse r, Response res) { try {/* w w w .java2 s . co m*/ OutputStream out = r.getOutputStream(); ObjectOutputStream outputToApplet = new ObjectOutputStream(out); outputToApplet.writeObject(res); outputToApplet.flush(); outputToApplet.close(); } catch (IOException e) { log.error("Failed to respond to request", e); } }
From source file:com.bskyb.cg.environments.hash.PersistentHash.java
private synchronized void appendEntryToStore(Message message) throws IOException { String filename = message.getKey(); File file = new File(dirname, filename); FileOutputStream fos = new FileOutputStream(file, true); BufferedOutputStream bos = new BufferedOutputStream(fos); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(message);/*from ww w . j a v a2s .co m*/ oos.flush(); oos.close(); fos.flush(); fos.close(); }
From source file:org.apache.hc.client5.http.impl.auth.TestBasicScheme.java
@Test public void testSerializationUnchallenged() throws Exception { final BasicScheme basicScheme = new BasicScheme(); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); final ObjectOutputStream out = new ObjectOutputStream(buffer); out.writeObject(basicScheme);//from w w w.ja v a 2s . c om out.flush(); final byte[] raw = buffer.toByteArray(); final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(raw)); final BasicScheme authScheme = (BasicScheme) in.readObject(); Assert.assertEquals(basicScheme.getName(), authScheme.getName()); Assert.assertEquals(basicScheme.getRealm(), authScheme.getRealm()); Assert.assertEquals(basicScheme.isChallengeComplete(), authScheme.isChallengeComplete()); }
From source file:org.LexGrid.LexBIG.caCore.client.proxy.ProxyUnwrappingHttpInvokerRequestExecutor.java
protected void writeRemoteInvocation(RemoteInvocation invocation, OutputStream os) throws IOException { ObjectOutputStream oos = new ProxyUnwrappingObjectStream(decorateOutputStream(os)); try {//from w w w. ja v a 2s .c o m doWriteRemoteInvocation(invocation, oos); oos.flush(); } finally { oos.close(); } }
From source file:org.kawanfw.file.reflection.ClassSerializer.java
/** * Serializes a class instance into a base64 String. * /*from www . ja va 2s . c o m*/ * @param element * the class instance to Serialize * @return the base64 string containing the serialized class instance * * @throws IOException * Any exception thrown by the underlying OutputStream. */ public String toBase64(E element) throws IOException { String serializedBase64 = null; ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(bos); oos.writeObject(element); oos.flush(); byte[] byteArray = bos.toByteArray(); serializedBase64 = Base64.byteArrayToBase64(byteArray); } finally { IOUtils.closeQuietly(oos); } return serializedBase64; }
From source file:org.apache.storm.hdfs.security.AutoHDFS.java
@SuppressWarnings("unchecked") private byte[] getHadoopCredentials(Map conf, final Configuration configuration) { try {/*ww w. ja va 2s.c o m*/ if (UserGroupInformation.isSecurityEnabled()) { login(configuration); final String topologySubmitterUser = (String) conf.get(Config.TOPOLOGY_SUBMITTER_PRINCIPAL); 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(); fileSystem.addDelegationTokens(hdfsPrincipal, 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.apache.hc.client5.http.impl.auth.TestBasicScheme.java
@Test public void testSerialization() throws Exception { final AuthChallenge authChallenge = parse("Basic realm=\"test\""); final BasicScheme basicScheme = new BasicScheme(); basicScheme.processChallenge(authChallenge, null); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); final ObjectOutputStream out = new ObjectOutputStream(buffer); out.writeObject(basicScheme);/*from ww w . java 2 s.co m*/ out.flush(); final byte[] raw = buffer.toByteArray(); final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(raw)); final BasicScheme authScheme = (BasicScheme) in.readObject(); Assert.assertEquals(basicScheme.getName(), authScheme.getName()); Assert.assertEquals(basicScheme.getRealm(), authScheme.getRealm()); Assert.assertEquals(basicScheme.isChallengeComplete(), authScheme.isChallengeComplete()); }