src/main/java/js/net/EventStream.java
protected void sendEvent(Event event) {
		write("data:");

		if (secretKey == null) {
			json.serialize(writer, event);
		} else {
			try {
				Cipher cipher = Cipher.getInstance(secretKey.getAlgorithm());
				cipher.init(Cipher.ENCRYPT_MODE, secretKey);

				// this overload of doFinal from Cipher class is able to perform single step encrypting
				// excerpt from API:
				// Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.
				byte[] encryptedMessage = cipher.doFinal(json.serialize(event));

				// encode encrypted event message with Base64 since content type should be text
				write(Base64.encode(encryptedMessage));
			} catch (InvalidKeyException | NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException e) {
				// we step here only for bugs on encryption provider:
				// secret key size is incorrect or key is not properly initialized
				// single step encryption using directly Cipher#doFinal is supposed to process all input at once
				// missing JVM default padding mechanism
				// bad padding occurring on encryption
				throw new BugError(e);
			} catch (NoSuchAlgorithmException e) {
				throw new BugError("Missing support for |%s| cryptographic algorithm.", secretKey.getAlgorithm());
			}
		}

		// end data field
		crlf();

		// single end of line is the mark for event end
		crlf();
		flush();
	}
protected void sendEvent(Event event) {
		write("data:");

		if (secretKey == null) {
			json.serialize(writer, event);
		} else {
			try {
				Cipher cipher = Cipher.getInstance(secretKey.getAlgorithm());
				cipher.init(Cipher.ENCRYPT_MODE, secretKey);

				// this overload of doFinal from Cipher class is able to perform single step encrypting
				// excerpt from API:
				// Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.
				byte[] encryptedMessage = cipher.doFinal(json.serialize(event));

				// encode encrypted event message with Base64 since content type should be text
				write(Base64.encode(encryptedMessage));
			} catch (InvalidKeyException | NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException e) {
				// we step here only for bugs on encryption provider:
				// secret key size is incorrect or key is not properly initialized
				// single step encryption using directly Cipher#doFinal is supposed to process all input at once
				// missing JVM default padding mechanism
				// bad padding occurring on encryption
				throw new BugError(e);
			} catch (NoSuchAlgorithmException e) {
				throw new BugError("Missing support for |%s| cryptographic algorithm.", secretKey.getAlgorithm());
			}
		}

		// end data field
		crlf();

		// single end of line is the mark for event end
		crlf();
		flush();
	}
protected void sendEvent ( Event event ) { write ( "data:" ) ; if ( secretKey == null ) { json . serialize ( writer , event ) ; } else { try { Cipher cipher = Cipher . getInstance ( secretKey . getAlgorithm ( ) ) ; cipher . init ( Cipher . ENCRYPT_MODE , secretKey ) ; // this overload of doFinal from Cipher class is able to perform single step encrypting
 // excerpt from API:
 // Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.
 byte [ ] encryptedMessage = cipher . doFinal ( json . serialize ( event ) ) ; // encode encrypted event message with Base64 since content type should be text
 write ( Base64 . encode ( encryptedMessage ) ) ; } catch ( InvalidKeyException | NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException e ) { // we step here only for bugs on encryption provider:
 // secret key size is incorrect or key is not properly initialized
 // single step encryption using directly Cipher#doFinal is supposed to process all input at once
 // missing JVM default padding mechanism
 // bad padding occurring on encryption
 throw new BugError ( e ) ; } catch ( NoSuchAlgorithmException e ) { throw new BugError ( "Missing support for |%s| cryptographic algorithm." , secretKey . getAlgorithm ( ) ) ; } } // end data field
 crlf ( ) ; // single end of line is the mark for event end
 crlf ( ) ; flush ( ) ; }
Send event instance to this event stream consumer. Compile a W3C Server-Sent event from <code>event</code> instance
argument and write it to this {@link #writer}. This event stream implementation does not use all W3C server-sent event
fields: only <code>event</code> and <code>data</code>, as folows:
<ul>
<li>event field stores event argument canonical class name,
<li>data field value is event argument instance serialized JSON.
</ul>
Just for those curious here is an sample of a serialized hypothetical event, as it is on wire:

<pre>
event:bb.hub.event.NotificationCRLF
data:{"id":213,"title":"Baby Server Admin","text":"Baby server was stopped.","timestamp":"2014-04-10T19:07:05Z","priority":"DEFAULT"}CRLF
CRLF
</pre>

@param event event instance.
Send event instance to this event stream consumer . Compile a W3C Server - Sent event from <code > event< / code > instance argument and write it to this { @link #writer } . This event stream implementation does not use all W3C server - sent event fields : only <code > event< / code > and <code > data< / code > as folows : <ul > <li > event field stores event argument canonical class name <li > data field value is event argument instance serialized JSON . < / ul > Just for those curious here is an sample of a serialized hypothetical event as it is on wire :