| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- /*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/assira
- */
- package net.ranides.assira.io;
- import edu.umd.cs.findbugs.annotations.SuppressWarnings;
- import java.io.Serializable;
- import java.util.Arrays;
- import net.ranides.assira.events.Event;
- /**
- *
- * @author ranides
- */
- @SuppressWarnings({
- "EI_EXPOSE_REP",
- "PMD"
- })
- public abstract class IORequest implements Event, Serializable {
- private static final long serialVersionUID = 1L;
- private static final class Li { // NOPMD lazy init idiom
- static final Close CLOSE = new Close();
- static final Flush FLUSH = new Flush();
- }
- public static Close close() {
- return Li.CLOSE;
- }
- public static Flush flush() {
- return Li.FLUSH;
- }
- public static WriteByte write(int value) {
- return new WriteByte(value);
- }
- public static WriteByteArray write(byte[] array) {
- return new WriteByteArray(Arrays.copyOf(array, array.length));
- }
- public static WriteByteArray write(byte[] array, int offset, int length) {
- return new WriteByteArray(Arrays.copyOfRange(array, offset, offset + length));
- }
- public static class Close extends IORequest {
- private static final long serialVersionUID = 1L;
- protected Close() {
- // do nothing
- }
- @Override
- public String toString() {
- return "IORequest.Close";
- }
- }
- public static class Flush extends IORequest {
- private static final long serialVersionUID = 1L;
- protected Flush() {
- // do nothing
- }
- @Override
- public String toString() {
- return "IORequest.Flush";
- }
- }
- public static class WriteByte extends IORequest {
- private static final long serialVersionUID = 1L;
- private final int data;
- protected WriteByte(int data) {
- this.data = data;
- }
- public final int data() {
- return data;
- }
- @Override
- public String toString() {
- return "IORequest.WriteByte: " + data;
- }
- }
- public static class WriteByteArray extends IORequest {
- private static final long serialVersionUID = 1L;
- private final byte[] data;
- protected WriteByteArray(byte[] data) {
- this.data = data;
- }
- public byte[] data() {
- return data;
- }
- @Override
- public String toString() {
- return "IORequest.WriteByteArray: " + data.length;
- }
- }
- }
|