You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by el...@apache.org on 2012/10/01 01:43:34 UTC
svn commit: r1392134 [10/16] - in /mina/branches/2.0:
mina-core/src/main/java/org/apache/mina/core/
mina-core/src/main/java/org/apache/mina/core/buffer/
mina-core/src/main/java/org/apache/mina/core/file/
mina-core/src/main/java/org/apache/mina/core/fil...
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioProcessor.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioProcessor.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioProcessor.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioProcessor.java Sun Sep 30 23:43:23 2012
@@ -103,8 +103,7 @@ public final class NioProcessor extends
protected void init(NioSession session) throws Exception {
SelectableChannel ch = (SelectableChannel) session.getChannel();
ch.configureBlocking(false);
- session.setSelectionKey(ch.register(selector, SelectionKey.OP_READ,
- session));
+ session.setSelectionKey(ch.register(selector, SelectionKey.OP_READ, session));
}
@Override
@@ -117,7 +116,6 @@ public final class NioProcessor extends
ch.close();
}
-
/**
* In the case we are using the java select() method, this method is used to
* trash the buggy selector and create a new one, registering all the
@@ -136,9 +134,9 @@ public final class NioProcessor extends
SelectableChannel ch = key.channel();
// Don't forget to attache the session, and back !
- NioSession session = (NioSession)key.attachment();
+ NioSession session = (NioSession) key.attachment();
SelectionKey newKey = ch.register(newSelector, key.interestOps(), session);
- session.setSelectionKey( newKey );
+ session.setSelectionKey(newKey);
}
// Now we can close the old selector and switch it
@@ -164,10 +162,8 @@ public final class NioProcessor extends
for (SelectionKey key : keys) {
SelectableChannel channel = key.channel();
- if ((((channel instanceof DatagramChannel) && !((DatagramChannel) channel)
- .isConnected()))
- || ((channel instanceof SocketChannel) && !((SocketChannel) channel)
- .isConnected())) {
+ if ((((channel instanceof DatagramChannel) && !((DatagramChannel) channel).isConnected()))
+ || ((channel instanceof SocketChannel) && !((SocketChannel) channel).isConnected())) {
// The channel is not connected anymore. Cancel
// the associated key then.
key.cancel();
@@ -217,22 +213,20 @@ public final class NioProcessor extends
@Override
protected boolean isInterestedInRead(NioSession session) {
SelectionKey key = session.getSelectionKey();
- return key.isValid() && ( (key.interestOps() & SelectionKey.OP_READ) != 0 );
+ return key.isValid() && ((key.interestOps() & SelectionKey.OP_READ) != 0);
}
@Override
protected boolean isInterestedInWrite(NioSession session) {
SelectionKey key = session.getSelectionKey();
- return key.isValid()
- && ( (key.interestOps() & SelectionKey.OP_WRITE) != 0 );
+ return key.isValid() && ((key.interestOps() & SelectionKey.OP_WRITE) != 0);
}
/**
* {@inheritDoc}
*/
@Override
- protected void setInterestedInRead(NioSession session, boolean isInterested)
- throws Exception {
+ protected void setInterestedInRead(NioSession session, boolean isInterested) throws Exception {
SelectionKey key = session.getSelectionKey();
int oldInterestOps = key.interestOps();
int newInterestOps = oldInterestOps;
@@ -252,8 +246,7 @@ public final class NioProcessor extends
* {@inheritDoc}
*/
@Override
- protected void setInterestedInWrite(NioSession session, boolean isInterested)
- throws Exception {
+ protected void setInterestedInWrite(NioSession session, boolean isInterested) throws Exception {
SelectionKey key = session.getSelectionKey();
if (key == null) {
@@ -281,8 +274,7 @@ public final class NioProcessor extends
}
@Override
- protected int write(NioSession session, IoBuffer buf, int length)
- throws Exception {
+ protected int write(NioSession session, IoBuffer buf, int length) throws Exception {
if (buf.remaining() <= length) {
return session.getChannel().write(buf.buf());
}
@@ -297,16 +289,14 @@ public final class NioProcessor extends
}
@Override
- protected int transferFile(NioSession session, FileRegion region, int length)
- throws Exception {
+ protected int transferFile(NioSession session, FileRegion region, int length) throws Exception {
try {
- return (int) region.getFileChannel().transferTo(
- region.getPosition(), length, session.getChannel());
+ return (int) region.getFileChannel().transferTo(region.getPosition(), length, session.getChannel());
} catch (IOException e) {
// Check to see if the IOException is being thrown due to
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5103988
String message = e.getMessage();
- if (( message != null ) && message.contains("temporarily unavailable")) {
+ if ((message != null) && message.contains("temporarily unavailable")) {
return 0;
}
@@ -318,8 +308,7 @@ public final class NioProcessor extends
* An encapsulating iterator around the {@link Selector#selectedKeys()} or
* the {@link Selector#keys()} iterator;
*/
- protected static class IoSessionIterator<NioSession> implements
- Iterator<NioSession> {
+ protected static class IoSessionIterator<NioSession> implements Iterator<NioSession> {
private final Iterator<SelectionKey> iterator;
/**
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java Sun Sep 30 23:43:23 2012
@@ -48,9 +48,8 @@ import org.apache.mina.transport.socket.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public final class NioSocketAcceptor
- extends AbstractPollingIoAcceptor<NioSession, ServerSocketChannel>
- implements SocketAcceptor {
+public final class NioSocketAcceptor extends AbstractPollingIoAcceptor<NioSession, ServerSocketChannel> implements
+ SocketAcceptor {
private volatile Selector selector;
@@ -104,7 +103,7 @@ public final class NioSocketAcceptor
protected void init() throws Exception {
selector = Selector.open();
}
-
+
/**
* {@inheritDoc}
*/
@@ -157,18 +156,17 @@ public final class NioSocketAcceptor
* {@inheritDoc}
*/
@Override
- protected NioSession accept(IoProcessor<NioSession> processor,
- ServerSocketChannel handle) throws Exception {
+ protected NioSession accept(IoProcessor<NioSession> processor, ServerSocketChannel handle) throws Exception {
SelectionKey key = handle.keyFor(selector);
-
- if ((key == null) || (!key.isValid()) || (!key.isAcceptable()) ) {
+
+ if ((key == null) || (!key.isValid()) || (!key.isAcceptable())) {
return null;
}
// accept the connection from the client
SocketChannel ch = handle.accept();
-
+
if (ch == null) {
return null;
}
@@ -180,26 +178,25 @@ public final class NioSocketAcceptor
* {@inheritDoc}
*/
@Override
- protected ServerSocketChannel open(SocketAddress localAddress)
- throws Exception {
+ protected ServerSocketChannel open(SocketAddress localAddress) throws Exception {
// Creates the listening ServerSocket
ServerSocketChannel channel = ServerSocketChannel.open();
-
+
boolean success = false;
-
+
try {
// This is a non blocking socket channel
channel.configureBlocking(false);
-
+
// Configure the server socket,
ServerSocket socket = channel.socket();
-
+
// Set the reuseAddress flag accordingly with the setting
socket.setReuseAddress(isReuseAddress());
-
+
// and bind.
socket.bind(localAddress, getBacklog());
-
+
// Register the channel within the selector for ACCEPT event
channel.register(selector, SelectionKey.OP_ACCEPT);
success = true;
@@ -215,8 +212,7 @@ public final class NioSocketAcceptor
* {@inheritDoc}
*/
@Override
- protected SocketAddress localAddress(ServerSocketChannel handle)
- throws Exception {
+ protected SocketAddress localAddress(ServerSocketChannel handle) throws Exception {
return handle.socket().getLocalSocketAddress();
}
@@ -252,11 +248,11 @@ public final class NioSocketAcceptor
@Override
protected void close(ServerSocketChannel handle) throws Exception {
SelectionKey key = handle.keyFor(selector);
-
+
if (key != null) {
key.cancel();
}
-
+
handle.close();
}
@@ -303,8 +299,8 @@ public final class NioSocketAcceptor
*/
public ServerSocketChannel next() {
SelectionKey key = iterator.next();
-
- if ( key.isValid() && key.isAcceptable() ) {
+
+ if (key.isValid() && key.isAcceptable()) {
return (ServerSocketChannel) key.channel();
}
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketConnector.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketConnector.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketConnector.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketConnector.java Sun Sep 30 23:43:23 2012
@@ -43,9 +43,8 @@ import org.apache.mina.transport.socket.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public final class NioSocketConnector
- extends AbstractPollingIoConnector<NioSession, SocketChannel>
- implements SocketConnector {
+public final class NioSocketConnector extends AbstractPollingIoConnector<NioSession, SocketChannel> implements
+ SocketConnector {
private volatile Selector selector;
@@ -90,7 +89,7 @@ public final class NioSocketConnector
super(new DefaultSocketSessionConfig(), executor, processor);
((DefaultSocketSessionConfig) getSessionConfig()).init(this);
}
-
+
/**
* Constructor for {@link NioSocketConnector} with default configuration which will use a built-in
* thread pool executor to manage the given number of processor instances. The processor class must have
@@ -102,8 +101,7 @@ public final class NioSocketConnector
* @see org.apache.mina.core.service.SimpleIoProcessorPool#SimpleIoProcessorPool(Class, Executor, int)
* @since 2.0.0-M4
*/
- public NioSocketConnector(Class<? extends IoProcessor<NioSession>> processorClass,
- int processorCount) {
+ public NioSocketConnector(Class<? extends IoProcessor<NioSession>> processorClass, int processorCount) {
super(new DefaultSocketSessionConfig(), processorClass, processorCount);
}
@@ -155,7 +153,7 @@ public final class NioSocketConnector
public SocketSessionConfig getSessionConfig() {
return (SocketSessionConfig) super.getSessionConfig();
}
-
+
/**
* {@inheritDoc}
*/
@@ -163,7 +161,7 @@ public final class NioSocketConnector
public InetSocketAddress getDefaultRemoteAddress() {
return (InetSocketAddress) super.getDefaultRemoteAddress();
}
-
+
/**
* {@inheritDoc}
*/
@@ -183,8 +181,7 @@ public final class NioSocketConnector
* {@inheritDoc}
*/
@Override
- protected boolean connect(SocketChannel handle, SocketAddress remoteAddress)
- throws Exception {
+ protected boolean connect(SocketChannel handle, SocketAddress remoteAddress) throws Exception {
return handle.connect(remoteAddress);
}
@@ -194,8 +191,8 @@ public final class NioSocketConnector
@Override
protected ConnectionRequest getConnectionRequest(SocketChannel handle) {
SelectionKey key = handle.keyFor(selector);
-
- if ((key == null) || (!key.isValid())) {
+
+ if ((key == null) || (!key.isValid())) {
return null;
}
@@ -208,11 +205,11 @@ public final class NioSocketConnector
@Override
protected void close(SocketChannel handle) throws Exception {
SelectionKey key = handle.keyFor(selector);
-
+
if (key != null) {
key.cancel();
}
-
+
handle.close();
}
@@ -227,7 +224,7 @@ public final class NioSocketConnector
if (key != null) {
key.cancel();
}
-
+
return true;
}
@@ -238,12 +235,10 @@ public final class NioSocketConnector
* {@inheritDoc}
*/
@Override
- protected SocketChannel newHandle(SocketAddress localAddress)
- throws Exception {
+ protected SocketChannel newHandle(SocketAddress localAddress) throws Exception {
SocketChannel ch = SocketChannel.open();
- int receiveBufferSize =
- (getSessionConfig()).getReceiveBufferSize();
+ int receiveBufferSize = (getSessionConfig()).getReceiveBufferSize();
if (receiveBufferSize > 65535) {
ch.socket().setReceiveBufferSize(receiveBufferSize);
}
@@ -267,8 +262,7 @@ public final class NioSocketConnector
* {@inheritDoc}
*/
@Override
- protected void register(SocketChannel handle, ConnectionRequest request)
- throws Exception {
+ protected void register(SocketChannel handle, ConnectionRequest request) throws Exception {
handle.register(selector, SelectionKey.OP_CONNECT, request);
}
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/DefaultVmPipeSessionConfig.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/DefaultVmPipeSessionConfig.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/DefaultVmPipeSessionConfig.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/DefaultVmPipeSessionConfig.java Sun Sep 30 23:43:23 2012
@@ -27,8 +27,7 @@ import org.apache.mina.core.session.IoSe
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-class DefaultVmPipeSessionConfig extends AbstractIoSessionConfig implements
- VmPipeSessionConfig {
+class DefaultVmPipeSessionConfig extends AbstractIoSessionConfig implements VmPipeSessionConfig {
DefaultVmPipeSessionConfig() {
// Do nothing
}
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipe.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipe.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipe.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipe.java Sun Sep 30 23:43:23 2012
@@ -36,8 +36,7 @@ class VmPipe {
private final IoServiceListenerSupport listeners;
- VmPipe(VmPipeAcceptor acceptor, VmPipeAddress address,
- IoHandler handler, IoServiceListenerSupport listeners) {
+ VmPipe(VmPipeAcceptor acceptor, VmPipeAddress address, IoHandler handler, IoServiceListenerSupport listeners) {
this.acceptor = acceptor;
this.address = address;
this.handler = handler;
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java Sun Sep 30 23:43:23 2012
@@ -42,10 +42,10 @@ import org.apache.mina.core.session.IoSe
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public final class VmPipeAcceptor extends AbstractIoAcceptor {
-
+
// object used for checking session idle
private IdleStatusChecker idleChecker;
-
+
static final Map<VmPipeAddress, VmPipe> boundHandlers = new HashMap<VmPipeAddress, VmPipe>();
/**
@@ -54,7 +54,7 @@ public final class VmPipeAcceptor extend
public VmPipeAcceptor() {
this(null);
}
-
+
/**
* Creates a new instance.
*/
@@ -104,19 +104,18 @@ public final class VmPipeAcceptor extend
Set<SocketAddress> newLocalAddresses = new HashSet<SocketAddress>();
synchronized (boundHandlers) {
- for (SocketAddress a: localAddresses) {
+ for (SocketAddress a : localAddresses) {
VmPipeAddress localAddress = (VmPipeAddress) a;
if (localAddress == null || localAddress.getPort() == 0) {
localAddress = null;
for (int i = 10000; i < Integer.MAX_VALUE; i++) {
VmPipeAddress newLocalAddress = new VmPipeAddress(i);
- if (!boundHandlers.containsKey(newLocalAddress) &&
- !newLocalAddresses.contains(newLocalAddress)) {
+ if (!boundHandlers.containsKey(newLocalAddress) && !newLocalAddresses.contains(newLocalAddress)) {
localAddress = newLocalAddress;
break;
}
}
-
+
if (localAddress == null) {
throw new IOException("No port available.");
}
@@ -125,17 +124,16 @@ public final class VmPipeAcceptor extend
} else if (boundHandlers.containsKey(localAddress)) {
throw new IOException("Address already bound: " + localAddress);
}
-
+
newLocalAddresses.add(localAddress);
}
- for (SocketAddress a: newLocalAddresses) {
+ for (SocketAddress a : newLocalAddresses) {
VmPipeAddress localAddress = (VmPipeAddress) a;
if (!boundHandlers.containsKey(localAddress)) {
- boundHandlers.put(localAddress, new VmPipe(this, localAddress,
- getHandler(), getListeners()));
+ boundHandlers.put(localAddress, new VmPipe(this, localAddress, getHandler(), getListeners()));
} else {
- for (SocketAddress a2: newLocalAddresses) {
+ for (SocketAddress a2 : newLocalAddresses) {
boundHandlers.remove(a2);
}
throw new IOException("Duplicate local address: " + a);
@@ -149,7 +147,7 @@ public final class VmPipeAcceptor extend
@Override
protected void unbind0(List<? extends SocketAddress> localAddresses) {
synchronized (boundHandlers) {
- for (SocketAddress a: localAddresses) {
+ for (SocketAddress a : localAddresses) {
boundHandlers.remove(a);
}
}
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAddress.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAddress.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAddress.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAddress.java Sun Sep 30 23:43:23 2012
@@ -75,7 +75,7 @@ public class VmPipeAddress extends Socke
if (port >= 0) {
return "vm:server:" + port;
}
-
+
return "vm:client:" + -port;
}
}
\ No newline at end of file
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java Sun Sep 30 23:43:23 2012
@@ -47,14 +47,14 @@ public final class VmPipeConnector exten
// object used for checking session idle
private IdleStatusChecker idleChecker;
-
+
/**
* Creates a new instance.
*/
public VmPipeConnector() {
this(null);
}
-
+
/**
* Creates a new instance.
*/
@@ -76,13 +76,11 @@ public final class VmPipeConnector exten
}
@Override
- protected ConnectFuture connect0(SocketAddress remoteAddress,
- SocketAddress localAddress,
- IoSessionInitializer<? extends ConnectFuture> sessionInitializer) {
+ protected ConnectFuture connect0(SocketAddress remoteAddress, SocketAddress localAddress,
+ IoSessionInitializer<? extends ConnectFuture> sessionInitializer) {
VmPipe entry = VmPipeAcceptor.boundHandlers.get(remoteAddress);
if (entry == null) {
- return DefaultConnectFuture.newFailedFuture(new IOException(
- "Endpoint unavailable: " + remoteAddress));
+ return DefaultConnectFuture.newFailedFuture(new IOException("Endpoint unavailable: " + remoteAddress));
}
DefaultConnectFuture future = new DefaultConnectFuture();
@@ -95,8 +93,7 @@ public final class VmPipeConnector exten
return DefaultConnectFuture.newFailedFuture(e);
}
- VmPipeSession localSession = new VmPipeSession(this,
- getListeners(), actualLocalAddress, getHandler(), entry);
+ VmPipeSession localSession = new VmPipeSession(this, getListeners(), actualLocalAddress, getHandler(), entry);
initSession(localSession, future, sessionInitializer);
@@ -121,8 +118,7 @@ public final class VmPipeConnector exten
((VmPipeAcceptor) remoteSession.getService()).doFinishSessionInitialization(remoteSession, null);
try {
IoFilterChain filterChain = remoteSession.getFilterChain();
- entry.getAcceptor().getFilterChainBuilder().buildFilterChain(
- filterChain);
+ entry.getAcceptor().getFilterChainBuilder().buildFilterChain(filterChain);
// The following sentences don't throw any exceptions.
entry.getListeners().fireSessionCreated(remoteSession);
@@ -172,8 +168,7 @@ public final class VmPipeConnector exten
private static class LocalAddressReclaimer implements IoFutureListener<IoFuture> {
public void operationComplete(IoFuture future) {
synchronized (TAKEN_LOCAL_ADDRESSES) {
- TAKEN_LOCAL_ADDRESSES.remove(future.getSession()
- .getLocalAddress());
+ TAKEN_LOCAL_ADDRESSES.remove(future.getSession().getLocalAddress());
}
}
}
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java Sun Sep 30 23:43:23 2012
@@ -69,7 +69,7 @@ public class AvailablePortFinder {
public static int getNextAvailable() {
try {
// Here, we simply return an available port found by the system
- return new ServerSocket( 0 ).getLocalPort();
+ return new ServerSocket(0).getLocalPort();
} catch (IOException ioe) {
throw new NoSuchElementException(ioe.getMessage());
}
@@ -83,8 +83,7 @@ public class AvailablePortFinder {
*/
public static int getNextAvailable(int fromPort) {
if (fromPort < MIN_PORT_NUMBER || fromPort > MAX_PORT_NUMBER) {
- throw new IllegalArgumentException("Invalid start port: "
- + fromPort);
+ throw new IllegalArgumentException("Invalid start port: " + fromPort);
}
for (int i = fromPort; i <= MAX_PORT_NUMBER; i++) {
@@ -93,8 +92,7 @@ public class AvailablePortFinder {
}
}
- throw new NoSuchElementException("Could not find an available port "
- + "above " + fromPort);
+ throw new NoSuchElementException("Could not find an available port " + "above " + fromPort);
}
/**
@@ -143,10 +141,8 @@ public class AvailablePortFinder {
* <code>fromPort</code> if greater than <code>toPort</code>.
*/
public static Set<Integer> getAvailablePorts(int fromPort, int toPort) {
- if (fromPort < MIN_PORT_NUMBER || toPort > MAX_PORT_NUMBER
- || fromPort > toPort) {
- throw new IllegalArgumentException("Invalid port range: "
- + fromPort + " ~ " + toPort);
+ if (fromPort < MIN_PORT_NUMBER || toPort > MAX_PORT_NUMBER || fromPort > toPort) {
+ throw new IllegalArgumentException("Invalid port range: " + fromPort + " ~ " + toPort);
}
Set<Integer> result = new TreeSet<Integer>();
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/Base64.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/Base64.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/Base64.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/Base64.java Sun Sep 30 23:43:23 2012
@@ -205,8 +205,7 @@ public class Base64 {
*/
public Object decode(Object pObject) {
if (!(pObject instanceof byte[])) {
- throw new InvalidParameterException(
- "Parameter supplied to Base64 decode is not a byte[]");
+ throw new InvalidParameterException("Parameter supplied to Base64 decode is not a byte[]");
}
return decode((byte[]) pObject);
}
@@ -252,8 +251,7 @@ public class Base64 {
// allow for extra length to account for the separator(s)
if (isChunked) {
- nbrChunks = (CHUNK_SEPARATOR.length == 0 ? 0 : (int) Math
- .ceil((float) encodedDataLength / CHUNK_SIZE));
+ nbrChunks = (CHUNK_SEPARATOR.length == 0 ? 0 : (int) Math.ceil((float) encodedDataLength / CHUNK_SIZE));
encodedDataLength += nbrChunks * CHUNK_SEPARATOR.length;
}
@@ -279,21 +277,16 @@ public class Base64 {
l = (byte) (b2 & 0x0f);
k = (byte) (b1 & 0x03);
- byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2)
- : (byte) ((b1) >> 2 ^ 0xc0);
- byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4)
- : (byte) ((b2) >> 4 ^ 0xf0);
- byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6)
- : (byte) ((b3) >> 6 ^ 0xfc);
+ byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
+ byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
+ byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc);
encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
//log.debug( "val2 = " + val2 );
//log.debug( "k4 = " + (k<<4) );
//log.debug( "vak = " + (val2 | (k<<4)) );
- encodedData[encodedIndex + 1] = lookUpBase64Alphabet[val2
- | (k << 4)];
- encodedData[encodedIndex + 2] = lookUpBase64Alphabet[(l << 2)
- | val3];
+ encodedData[encodedIndex + 1] = lookUpBase64Alphabet[val2 | (k << 4)];
+ encodedData[encodedIndex + 2] = lookUpBase64Alphabet[(l << 2) | val3];
encodedData[encodedIndex + 3] = lookUpBase64Alphabet[b3 & 0x3f];
encodedIndex += 4;
@@ -302,11 +295,9 @@ public class Base64 {
if (isChunked) {
// this assumes that CHUNK_SIZE % 4 == 0
if (encodedIndex == nextSeparatorIndex) {
- System.arraycopy(CHUNK_SEPARATOR, 0, encodedData,
- encodedIndex, CHUNK_SEPARATOR.length);
+ System.arraycopy(CHUNK_SEPARATOR, 0, encodedData, encodedIndex, CHUNK_SEPARATOR.length);
chunksSoFar++;
- nextSeparatorIndex = (CHUNK_SIZE * (chunksSoFar + 1))
- + (chunksSoFar * CHUNK_SEPARATOR.length);
+ nextSeparatorIndex = (CHUNK_SIZE * (chunksSoFar + 1)) + (chunksSoFar * CHUNK_SEPARATOR.length);
encodedIndex += CHUNK_SEPARATOR.length;
}
}
@@ -320,8 +311,7 @@ public class Base64 {
k = (byte) (b1 & 0x03);
//log.debug("b1=" + b1);
//log.debug("b1<<2 = " + (b1>>2) );
- byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2)
- : (byte) ((b1) >> 2 ^ 0xc0);
+ byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
encodedData[encodedIndex + 1] = lookUpBase64Alphabet[k << 4];
encodedData[encodedIndex + 2] = PAD;
@@ -333,14 +323,11 @@ public class Base64 {
l = (byte) (b2 & 0x0f);
k = (byte) (b1 & 0x03);
- byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2)
- : (byte) ((b1) >> 2 ^ 0xc0);
- byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4)
- : (byte) ((b2) >> 4 ^ 0xf0);
+ byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
+ byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
- encodedData[encodedIndex + 1] = lookUpBase64Alphabet[val2
- | (k << 4)];
+ encodedData[encodedIndex + 1] = lookUpBase64Alphabet[val2 | (k << 4)];
encodedData[encodedIndex + 2] = lookUpBase64Alphabet[l << 2];
encodedData[encodedIndex + 3] = PAD;
}
@@ -348,8 +335,7 @@ public class Base64 {
if (isChunked) {
// we also add a separator to the end of the final chunk.
if (chunksSoFar < nbrChunks) {
- System.arraycopy(CHUNK_SEPARATOR, 0, encodedData,
- encodedDataLength - CHUNK_SEPARATOR.length,
+ System.arraycopy(CHUNK_SEPARATOR, 0, encodedData, encodedDataLength - CHUNK_SEPARATOR.length,
CHUNK_SEPARATOR.length);
}
}
@@ -495,8 +481,7 @@ public class Base64 {
*/
public Object encode(Object pObject) {
if (!(pObject instanceof byte[])) {
- throw new InvalidParameterException(
- "Parameter supplied to Base64 encode is not a byte[]");
+ throw new InvalidParameterException("Parameter supplied to Base64 encode is not a byte[]");
}
return encode((byte[]) pObject);
}
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/CircularQueue.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/CircularQueue.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/CircularQueue.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/CircularQueue.java Sun Sep 30 23:43:23 2012
@@ -39,15 +39,20 @@ public class CircularQueue<E> extends Ab
/** The initial capacity of the list */
private final int initialCapacity;
-
+
// XXX: This volatile keyword here is a workaround for SUN Java Compiler bug,
// which produces buggy byte code. I don't event know why adding a volatile
// fixes the problem. Eclipse Java Compiler seems to produce correct byte code.
private volatile Object[] items;
+
private int mask;
+
private int first = 0;
+
private int last = 0;
+
private boolean full;
+
private int shrinkThreshold;
/**
@@ -56,7 +61,7 @@ public class CircularQueue<E> extends Ab
public CircularQueue() {
this(DEFAULT_CAPACITY);
}
-
+
public CircularQueue(int initialCapacity) {
int actualCapacity = normalizeCapacity(initialCapacity);
items = new Object[actualCapacity];
@@ -70,7 +75,7 @@ public class CircularQueue<E> extends Ab
*/
private static int normalizeCapacity(int initialCapacity) {
int actualCapacity = 1;
-
+
while (actualCapacity < initialCapacity) {
actualCapacity <<= 1;
if (actualCapacity < 0) {
@@ -108,7 +113,7 @@ public class CircularQueue<E> extends Ab
Object ret = items[first];
items[first] = null;
decreaseSize();
-
+
if (first == last) {
first = last = 0;
}
@@ -121,7 +126,7 @@ public class CircularQueue<E> extends Ab
if (item == null) {
throw new IllegalArgumentException("item");
}
-
+
expandIfNeeded();
items[last] = item;
increaseSize();
@@ -154,18 +159,17 @@ public class CircularQueue<E> extends Ab
if (full) {
return capacity();
}
-
+
if (last >= first) {
return last - first;
}
return last - first + capacity();
}
-
+
@Override
public String toString() {
- return "first=" + first + ", last=" + last + ", size=" + size()
- + ", mask = " + mask;
+ return "first=" + first + ", last=" + last + ", size=" + size() + ", mask = " + mask;
}
private void checkIndex(int idx) {
@@ -194,14 +198,14 @@ public class CircularQueue<E> extends Ab
final int oldLen = items.length;
final int newLen = oldLen << 1;
Object[] tmp = new Object[newLen];
-
+
if (first < last) {
System.arraycopy(items, first, tmp, 0, last - first);
} else {
System.arraycopy(items, first, tmp, 0, oldLen - first);
System.arraycopy(items, 0, tmp, oldLen - first, last);
}
-
+
first = 0;
last = oldLen;
items = tmp;
@@ -211,7 +215,7 @@ public class CircularQueue<E> extends Ab
}
}
}
-
+
private void shrinkIfNeeded() {
int size = size();
if (size <= shrinkThreshold) {
@@ -221,11 +225,11 @@ public class CircularQueue<E> extends Ab
if (size == newLen) {
newLen <<= 1;
}
-
+
if (newLen >= oldLen) {
return;
}
-
+
if (newLen < initialCapacity) {
if (oldLen == initialCapacity) {
return;
@@ -233,9 +237,9 @@ public class CircularQueue<E> extends Ab
newLen = initialCapacity;
}
-
+
Object[] tmp = new Object[newLen];
-
+
// Copy only when there's something to copy.
if (size > 0) {
if (first < last) {
@@ -245,7 +249,7 @@ public class CircularQueue<E> extends Ab
System.arraycopy(items, 0, tmp, oldLen - first, last);
}
}
-
+
first = 0;
last = size;
items = tmp;
@@ -284,18 +288,14 @@ public class CircularQueue<E> extends Ab
// Make a room for a new element.
if (first < last) {
- System
- .arraycopy(items, realIdx, items, realIdx + 1, last
- - realIdx);
+ System.arraycopy(items, realIdx, items, realIdx + 1, last - realIdx);
} else {
if (realIdx >= first) {
System.arraycopy(items, 0, items, 1, last);
items[0] = items[items.length - 1];
- System.arraycopy(items, realIdx, items, realIdx + 1,
- items.length - realIdx - 1);
+ System.arraycopy(items, realIdx, items, realIdx + 1, items.length - realIdx - 1);
} else {
- System.arraycopy(items, realIdx, items, realIdx + 1, last
- - realIdx);
+ System.arraycopy(items, realIdx, items, realIdx + 1, last - realIdx);
}
}
@@ -320,13 +320,11 @@ public class CircularQueue<E> extends Ab
System.arraycopy(items, first, items, first + 1, realIdx - first);
} else {
if (realIdx >= first) {
- System.arraycopy(items, first, items, first + 1, realIdx
- - first);
+ System.arraycopy(items, first, items, first + 1, realIdx - first);
} else {
System.arraycopy(items, 0, items, 1, realIdx);
items[0] = items[items.length - 1];
- System.arraycopy(items, first, items, first + 1, items.length
- - first - 1);
+ System.arraycopy(items, first, items, first + 1, items.length - first - 1);
}
}
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/ExceptionMonitor.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/ExceptionMonitor.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/ExceptionMonitor.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/ExceptionMonitor.java Sun Sep 30 23:43:23 2012
@@ -19,8 +19,6 @@
*/
package org.apache.mina.util;
-
-
/**
* Monitors uncaught exceptions. {@link #exceptionCaught(Throwable)} is
* invoked when there are any uncaught exceptions.
@@ -55,7 +53,7 @@ public abstract class ExceptionMonitor {
if (monitor == null) {
monitor = new DefaultExceptionMonitor();
}
-
+
instance = monitor;
}
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/ExpiringMap.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/ExpiringMap.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/ExpiringMap.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/ExpiringMap.java Sun Sep 30 23:43:23 2012
@@ -35,7 +35,7 @@ import java.util.concurrent.locks.Reentr
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public class ExpiringMap<K, V> implements Map<K, V> {
-
+
/**
* The default value, 60
*/
@@ -84,14 +84,12 @@ public class ExpiringMap<K, V> implement
* The time between checks to see if a value should be removed (seconds)
*/
public ExpiringMap(int timeToLive, int expirationInterval) {
- this(new ConcurrentHashMap<K, ExpiringObject>(),
- new CopyOnWriteArrayList<ExpirationListener<V>>(), timeToLive,
+ this(new ConcurrentHashMap<K, ExpiringObject>(), new CopyOnWriteArrayList<ExpirationListener<V>>(), timeToLive,
expirationInterval);
}
private ExpiringMap(ConcurrentHashMap<K, ExpiringObject> delegate,
- CopyOnWriteArrayList<ExpirationListener<V>> expirationListeners,
- int timeToLive, int expirationInterval) {
+ CopyOnWriteArrayList<ExpirationListener<V>> expirationListeners, int timeToLive, int expirationInterval) {
this.delegate = delegate;
this.expirationListeners = expirationListeners;
@@ -101,8 +99,7 @@ public class ExpiringMap<K, V> implement
}
public V put(K key, V value) {
- ExpiringObject answer = delegate.put(key, new ExpiringObject(key,
- value, System.currentTimeMillis()));
+ ExpiringObject answer = delegate.put(key, new ExpiringObject(key, value, System.currentTimeMillis()));
if (answer == null) {
return null;
}
@@ -183,8 +180,7 @@ public class ExpiringMap<K, V> implement
expirationListeners.add(listener);
}
- public void removeExpirationListener(
- ExpirationListener<V> listener) {
+ public void removeExpirationListener(ExpirationListener<V> listener) {
expirationListeners.remove(listener);
}
@@ -219,8 +215,7 @@ public class ExpiringMap<K, V> implement
ExpiringObject(K key, V value, long lastAccessTime) {
if (value == null) {
- throw new IllegalArgumentException(
- "An expiring object cannot be null.");
+ throw new IllegalArgumentException("An expiring object cannot be null.");
}
this.key = key;
@@ -271,7 +266,7 @@ public class ExpiringMap<K, V> implement
* A Thread that monitors an {@link ExpiringMap} and will remove
* elements that have passed the threshold.
*
- */
+ */
public class Expirer implements Runnable {
private final ReadWriteLock stateLock = new ReentrantReadWriteLock();
@@ -288,8 +283,7 @@ public class ExpiringMap<K, V> implement
*
*/
public Expirer() {
- expirerThread = new Thread(this, "ExpiringMapExpirer-"
- + expirerCount++);
+ expirerThread = new Thread(this, "ExpiringMapExpirer-" + expirerCount++);
expirerThread.setDaemon(true);
}
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/IdentityHashSet.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/IdentityHashSet.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/IdentityHashSet.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/IdentityHashSet.java Sun Sep 30 23:43:23 2012
@@ -35,7 +35,7 @@ public class IdentityHashSet<E> extends
public IdentityHashSet() {
super(new IdentityHashMap<E, Boolean>());
}
-
+
public IdentityHashSet(int expectedMaxSize) {
super(new IdentityHashMap<E, Boolean>(expectedMaxSize));
}
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/LazyInitializedCacheMap.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/LazyInitializedCacheMap.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/LazyInitializedCacheMap.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/LazyInitializedCacheMap.java Sun Sep 30 23:43:23 2012
@@ -66,14 +66,14 @@ public class LazyInitializedCacheMap<K,
public LazyInitializedCacheMap() {
this.cache = new ConcurrentHashMap<K, LazyInitializer<V>>();
}
-
+
/**
* This constructor allows to provide a fine tuned {@link ConcurrentHashMap}
* to stick with each special case the user needs.
*/
public LazyInitializedCacheMap(final ConcurrentHashMap<K, LazyInitializer<V>> map) {
this.cache = map;
- }
+ }
/**
* {@inheritDoc}
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/Log4jXmlFormatter.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/Log4jXmlFormatter.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/Log4jXmlFormatter.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/Log4jXmlFormatter.java Sun Sep 30 23:43:23 2012
@@ -47,10 +47,13 @@ import org.slf4j.MDC;
public class Log4jXmlFormatter extends Formatter {
private final int DEFAULT_SIZE = 256;
+
private final int UPPER_LIMIT = 2048;
private StringBuffer buf = new StringBuffer(DEFAULT_SIZE);
+
private boolean locationInfo = false;
+
private boolean properties = false;
/**
@@ -144,12 +147,12 @@ public class Log4jXmlFormatter extends F
Map contextMap = MDC.getCopyOfContextMap();
if (contextMap != null) {
Set keySet = contextMap.keySet();
- if (( keySet != null ) && ( keySet.size() > 0 )) {
+ if ((keySet != null) && (keySet.size() > 0)) {
buf.append("<log4j:properties>\r\n");
Object[] keys = keySet.toArray();
Arrays.sort(keys);
for (Object key1 : keys) {
- String key = (key1 == null?"":key1.toString());
+ String key = (key1 == null ? "" : key1.toString());
Object val = contextMap.get(key);
if (val != null) {
buf.append("<log4j:data name=\"");
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/MapBackedSet.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/MapBackedSet.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/MapBackedSet.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/MapBackedSet.java Sun Sep 30 23:43:23 2012
@@ -34,7 +34,7 @@ import java.util.Set;
public class MapBackedSet<E> extends AbstractSet<E> implements Serializable {
private static final long serialVersionUID = -8347878570391674042L;
-
+
protected final Map<E, Boolean> map;
public MapBackedSet(Map<E, Boolean> map) {
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/NamePreservingRunnable.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/NamePreservingRunnable.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/NamePreservingRunnable.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/NamePreservingRunnable.java Sun Sep 30 23:43:23 2012
@@ -32,7 +32,7 @@ public class NamePreservingRunnable impl
/** The runnable name */
private final String newName;
-
+
/** The runnable task */
private final Runnable runnable;
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/SynchronizedQueue.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/SynchronizedQueue.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/SynchronizedQueue.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/SynchronizedQueue.java Sun Sep 30 23:43:23 2012
@@ -31,15 +31,15 @@ import java.util.Queue;
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public class SynchronizedQueue<E> implements Queue<E>, Serializable {
-
+
private static final long serialVersionUID = -1439242290701194806L;
-
+
private final Queue<E> q;
public SynchronizedQueue(Queue<E> q) {
this.q = q;
}
-
+
public synchronized boolean add(E e) {
return q.add(e);
}
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/Transform.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/Transform.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/Transform.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/Transform.java Sun Sep 30 23:43:23 2012
@@ -35,10 +35,14 @@ import java.util.ArrayList;
*/
public class Transform {
- private static final String CDATA_START = "<![CDATA[";
- private static final String CDATA_END = "]]>";
+ private static final String CDATA_START = "<![CDATA[";
+
+ private static final String CDATA_END = "]]>";
+
private static final String CDATA_PSEUDO_END = "]]>";
+
private static final String CDATA_EMBEDED_END = CDATA_END + CDATA_PSEUDO_END + CDATA_START;
+
private static final int CDATA_END_LEN = CDATA_END.length();
/**
@@ -54,12 +58,10 @@ public class Transform {
// Check if the string is null, zero length or devoid of special characters
// if so, return what was sent in.
- if(input == null
- || input.length() == 0
- || (input.indexOf('"') == -1 &&
- input.indexOf('&') == -1 &&
- input.indexOf('<') == -1 &&
- input.indexOf('>') == -1)) {
+ if (input == null
+ || input.length() == 0
+ || (input.indexOf('"') == -1 && input.indexOf('&') == -1 && input.indexOf('<') == -1 && input
+ .indexOf('>') == -1)) {
return input;
}
@@ -67,17 +69,17 @@ public class Transform {
char ch;
int len = input.length();
- for(int i=0; i < len; i++) {
+ for (int i = 0; i < len; i++) {
ch = input.charAt(i);
if (ch > '>') {
buf.append(ch);
- } else if(ch == '<') {
+ } else if (ch == '<') {
buf.append("<");
- } else if(ch == '>') {
+ } else if (ch == '>') {
buf.append(">");
- } else if(ch == '&') {
+ } else if (ch == '&') {
buf.append("&");
- } else if(ch == '"') {
+ } else if (ch == '"') {
buf.append(""");
} else {
buf.append(ch);
@@ -95,8 +97,7 @@ public class Transform {
* section are the responsibility of the calling method.
* @param str The String that is inserted into an existing CDATA Section within buf.
* */
- static public void appendEscapingCDATA(final StringBuffer buf,
- final String str) {
+ static public void appendEscapingCDATA(final StringBuffer buf, final String str) {
if (str != null) {
int end = str.indexOf(CDATA_END);
if (end < 0) {
@@ -132,11 +133,11 @@ public class Transform {
ArrayList<String> lines = new ArrayList<String>();
try {
String line = reader.readLine();
- while(line != null) {
+ while (line != null) {
lines.add(line);
line = reader.readLine();
}
- } catch(IOException ex) {
+ } catch (IOException ex) {
lines.add(ex.toString());
}
String[] rep = new String[lines.size()];
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/AbstractByteArray.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/AbstractByteArray.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/AbstractByteArray.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/AbstractByteArray.java Sun Sep 30 23:43:23 2012
@@ -19,7 +19,6 @@
*/
package org.apache.mina.util.byteaccess;
-
/**
*
* Abstract class that implements {@link ByteArray}. This class will only be
@@ -27,62 +26,49 @@ package org.apache.mina.util.byteaccess;
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-abstract class AbstractByteArray implements ByteArray
-{
+abstract class AbstractByteArray implements ByteArray {
/**
* @inheritDoc
*/
- public final int length()
- {
+ public final int length() {
return last() - first();
}
-
/**
* @inheritDoc
*/
@Override
- public final boolean equals( Object other )
- {
+ public final boolean equals(Object other) {
// Optimization: compare pointers.
- if ( other == this )
- {
+ if (other == this) {
return true;
}
// Compare types.
- if ( !( other instanceof ByteArray ) )
- {
+ if (!(other instanceof ByteArray)) {
return false;
}
- ByteArray otherByteArray = ( ByteArray ) other;
+ ByteArray otherByteArray = (ByteArray) other;
// Compare properties.
- if ( first() != otherByteArray.first() || last() != otherByteArray.last()
- || !order().equals( otherByteArray.order() ) )
- {
+ if (first() != otherByteArray.first() || last() != otherByteArray.last()
+ || !order().equals(otherByteArray.order())) {
return false;
}
// Compare bytes.
Cursor cursor = cursor();
Cursor otherCursor = otherByteArray.cursor();
- for ( int remaining = cursor.getRemaining(); remaining > 0; )
- {
+ for (int remaining = cursor.getRemaining(); remaining > 0;) {
// Optimization: prefer int comparisons over byte comparisons
- if ( remaining >= 4 )
- {
+ if (remaining >= 4) {
int i = cursor.getInt();
int otherI = otherCursor.getInt();
- if ( i != otherI )
- {
+ if (i != otherI) {
return false;
}
- }
- else
- {
+ } else {
byte b = cursor.get();
byte otherB = otherCursor.get();
- if ( b != otherB )
- {
+ if (b != otherB) {
return false;
}
}
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/BufferByteArray.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/BufferByteArray.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/BufferByteArray.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/BufferByteArray.java Sun Sep 30 23:43:23 2012
@@ -19,13 +19,11 @@
*/
package org.apache.mina.util.byteaccess;
-
import java.nio.ByteOrder;
import java.util.Collections;
import org.apache.mina.core.buffer.IoBuffer;
-
/**
* A <code>ByteArray</code> backed by a <code>IoBuffer</code>. This class
* is abstract. Subclasses need to override the <code>free()</code> method. An
@@ -34,8 +32,7 @@ import org.apache.mina.core.buffer.IoBuf
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public abstract class BufferByteArray extends AbstractByteArray
-{
+public abstract class BufferByteArray extends AbstractByteArray {
/**
* The backing <code>IoBuffer</code>.
@@ -50,505 +47,399 @@ public abstract class BufferByteArray ex
* @param bb
* The backing buffer
*/
- public BufferByteArray( IoBuffer bb )
- {
+ public BufferByteArray(IoBuffer bb) {
this.bb = bb;
}
-
/**
* @inheritDoc
*/
- public Iterable<IoBuffer> getIoBuffers()
- {
- return Collections.singletonList( bb );
+ public Iterable<IoBuffer> getIoBuffers() {
+ return Collections.singletonList(bb);
}
-
/**
* @inheritDoc
*/
- public IoBuffer getSingleIoBuffer()
- {
+ public IoBuffer getSingleIoBuffer() {
return bb;
}
-
/**
* @inheritDoc
*
* Calling <code>free()</code> on the returned slice has no effect.
*/
- public ByteArray slice( int index, int length )
- {
+ public ByteArray slice(int index, int length) {
int oldLimit = bb.limit();
- bb.position( index );
- bb.limit( index + length );
+ bb.position(index);
+ bb.limit(index + length);
IoBuffer slice = bb.slice();
- bb.limit( oldLimit );
- return new BufferByteArray( slice )
- {
+ bb.limit(oldLimit);
+ return new BufferByteArray(slice) {
@Override
- public void free()
- {
+ public void free() {
// Do nothing.
}
};
}
-
/**
* @inheritDoc
*/
public abstract void free();
-
/**
* @inheritDoc
*/
- public Cursor cursor()
- {
+ public Cursor cursor() {
return new CursorImpl();
}
-
/**
* @inheritDoc
*/
- public Cursor cursor( int index )
- {
- return new CursorImpl( index );
+ public Cursor cursor(int index) {
+ return new CursorImpl(index);
}
-
/**
* @inheritDoc
*/
- public int first()
- {
+ public int first() {
return 0;
}
-
/**
* @inheritDoc
*/
- public int last()
- {
+ public int last() {
return bb.limit();
}
-
/**
* @inheritDoc
*/
- public ByteOrder order()
- {
+ public ByteOrder order() {
return bb.order();
}
-
/**
* @inheritDoc
*/
- public void order( ByteOrder order )
- {
- bb.order( order );
+ public void order(ByteOrder order) {
+ bb.order(order);
}
-
/**
* @inheritDoc
*/
- public byte get( int index )
- {
- return bb.get( index );
+ public byte get(int index) {
+ return bb.get(index);
}
-
/**
* @inheritDoc
*/
- public void put( int index, byte b )
- {
- bb.put( index, b );
+ public void put(int index, byte b) {
+ bb.put(index, b);
}
-
/**
* @inheritDoc
*/
- public void get( int index, IoBuffer other )
- {
- bb.position( index );
- other.put( bb );
+ public void get(int index, IoBuffer other) {
+ bb.position(index);
+ other.put(bb);
}
-
/**
* @inheritDoc
*/
- public void put( int index, IoBuffer other )
- {
- bb.position( index );
- bb.put( other );
+ public void put(int index, IoBuffer other) {
+ bb.position(index);
+ bb.put(other);
}
-
/**
* @inheritDoc
*/
- public short getShort( int index )
- {
- return bb.getShort( index );
+ public short getShort(int index) {
+ return bb.getShort(index);
}
-
/**
* @inheritDoc
*/
- public void putShort( int index, short s )
- {
- bb.putShort( index, s );
+ public void putShort(int index, short s) {
+ bb.putShort(index, s);
}
-
/**
* @inheritDoc
*/
- public int getInt( int index )
- {
- return bb.getInt( index );
+ public int getInt(int index) {
+ return bb.getInt(index);
}
-
/**
* @inheritDoc
*/
- public void putInt( int index, int i )
- {
- bb.putInt( index, i );
+ public void putInt(int index, int i) {
+ bb.putInt(index, i);
}
-
/**
* @inheritDoc
*/
- public long getLong( int index )
- {
- return bb.getLong( index );
+ public long getLong(int index) {
+ return bb.getLong(index);
}
-
/**
* @inheritDoc
*/
- public void putLong( int index, long l )
- {
- bb.putLong( index, l );
+ public void putLong(int index, long l) {
+ bb.putLong(index, l);
}
-
/**
* @inheritDoc
*/
- public float getFloat( int index )
- {
- return bb.getFloat( index );
+ public float getFloat(int index) {
+ return bb.getFloat(index);
}
-
/**
* @inheritDoc
*/
- public void putFloat( int index, float f )
- {
- bb.putFloat( index, f );
+ public void putFloat(int index, float f) {
+ bb.putFloat(index, f);
}
-
/**
* @inheritDoc
*/
- public double getDouble( int index )
- {
- return bb.getDouble( index );
+ public double getDouble(int index) {
+ return bb.getDouble(index);
}
-
/**
* @inheritDoc
*/
- public void putDouble( int index, double d )
- {
- bb.putDouble( index, d );
+ public void putDouble(int index, double d) {
+ bb.putDouble(index, d);
}
-
/**
* @inheritDoc
*/
- public char getChar( int index )
- {
- return bb.getChar( index );
+ public char getChar(int index) {
+ return bb.getChar(index);
}
-
/**
* @inheritDoc
*/
- public void putChar( int index, char c )
- {
- bb.putChar( index, c );
+ public void putChar(int index, char c) {
+ bb.putChar(index, c);
}
- private class CursorImpl implements Cursor
- {
+ private class CursorImpl implements Cursor {
private int index;
-
- public CursorImpl()
- {
+ public CursorImpl() {
// This space intentionally blank.
}
-
- public CursorImpl( int index )
- {
- setIndex( index );
+ public CursorImpl(int index) {
+ setIndex(index);
}
-
/**
* @inheritDoc
*/
- public int getRemaining()
- {
+ public int getRemaining() {
return last() - index;
}
-
/**
* @inheritDoc
*/
- public boolean hasRemaining()
- {
+ public boolean hasRemaining() {
return getRemaining() > 0;
}
-
/**
* @inheritDoc
*/
- public int getIndex()
- {
+ public int getIndex() {
return index;
}
-
/**
* @inheritDoc
*/
- public void setIndex( int index )
- {
- if ( index < 0 || index > last() )
- {
+ public void setIndex(int index) {
+ if (index < 0 || index > last()) {
throw new IndexOutOfBoundsException();
}
this.index = index;
}
-
- public void skip( int length )
- {
- setIndex( index + length );
+ public void skip(int length) {
+ setIndex(index + length);
}
-
- public ByteArray slice( int length )
- {
- ByteArray slice = BufferByteArray.this.slice( index, length );
+ public ByteArray slice(int length) {
+ ByteArray slice = BufferByteArray.this.slice(index, length);
index += length;
return slice;
}
-
/**
* @inheritDoc
*/
- public ByteOrder order()
- {
+ public ByteOrder order() {
return BufferByteArray.this.order();
}
-
/**
* @inheritDoc
*/
- public byte get()
- {
- byte b = BufferByteArray.this.get( index );
+ public byte get() {
+ byte b = BufferByteArray.this.get(index);
index += 1;
return b;
}
-
/**
* @inheritDoc
*/
- public void put( byte b )
- {
- BufferByteArray.this.put( index, b );
+ public void put(byte b) {
+ BufferByteArray.this.put(index, b);
index += 1;
}
-
/**
* @inheritDoc
*/
- public void get( IoBuffer bb )
- {
- int size = Math.min( getRemaining(), bb.remaining() );
- BufferByteArray.this.get( index, bb );
+ public void get(IoBuffer bb) {
+ int size = Math.min(getRemaining(), bb.remaining());
+ BufferByteArray.this.get(index, bb);
index += size;
}
-
/**
* @inheritDoc
*/
- public void put( IoBuffer bb )
- {
+ public void put(IoBuffer bb) {
int size = bb.remaining();
- BufferByteArray.this.put( index, bb );
+ BufferByteArray.this.put(index, bb);
index += size;
}
-
/**
* @inheritDoc
*/
- public short getShort()
- {
- short s = BufferByteArray.this.getShort( index );
+ public short getShort() {
+ short s = BufferByteArray.this.getShort(index);
index += 2;
return s;
}
-
/**
* @inheritDoc
*/
- public void putShort( short s )
- {
- BufferByteArray.this.putShort( index, s );
+ public void putShort(short s) {
+ BufferByteArray.this.putShort(index, s);
index += 2;
}
-
/**
* @inheritDoc
*/
- public int getInt()
- {
- int i = BufferByteArray.this.getInt( index );
+ public int getInt() {
+ int i = BufferByteArray.this.getInt(index);
index += 4;
return i;
}
-
/**
* @inheritDoc
*/
- public void putInt( int i )
- {
- BufferByteArray.this.putInt( index, i );
+ public void putInt(int i) {
+ BufferByteArray.this.putInt(index, i);
index += 4;
}
-
/**
* @inheritDoc
*/
- public long getLong()
- {
- long l = BufferByteArray.this.getLong( index );
+ public long getLong() {
+ long l = BufferByteArray.this.getLong(index);
index += 8;
return l;
}
-
/**
* @inheritDoc
*/
- public void putLong( long l )
- {
- BufferByteArray.this.putLong( index, l );
+ public void putLong(long l) {
+ BufferByteArray.this.putLong(index, l);
index += 8;
}
-
/**
* @inheritDoc
*/
- public float getFloat()
- {
- float f = BufferByteArray.this.getFloat( index );
+ public float getFloat() {
+ float f = BufferByteArray.this.getFloat(index);
index += 4;
return f;
}
-
/**
* @inheritDoc
*/
- public void putFloat( float f )
- {
- BufferByteArray.this.putFloat( index, f );
+ public void putFloat(float f) {
+ BufferByteArray.this.putFloat(index, f);
index += 4;
}
-
/**
* @inheritDoc
*/
- public double getDouble()
- {
- double d = BufferByteArray.this.getDouble( index );
+ public double getDouble() {
+ double d = BufferByteArray.this.getDouble(index);
index += 8;
return d;
}
-
/**
* @inheritDoc
*/
- public void putDouble( double d )
- {
- BufferByteArray.this.putDouble( index, d );
+ public void putDouble(double d) {
+ BufferByteArray.this.putDouble(index, d);
index += 8;
}
-
/**
* @inheritDoc
*/
- public char getChar()
- {
- char c = BufferByteArray.this.getChar( index );
+ public char getChar() {
+ char c = BufferByteArray.this.getChar(index);
index += 2;
return c;
}
-
/**
* @inheritDoc
*/
- public void putChar( char c )
- {
- BufferByteArray.this.putChar( index, c );
+ public void putChar(char c) {
+ BufferByteArray.this.putChar(index, c);
index += 2;
}
}
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/ByteArray.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/ByteArray.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/ByteArray.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/ByteArray.java Sun Sep 30 23:43:23 2012
@@ -19,44 +19,37 @@
*/
package org.apache.mina.util.byteaccess;
-
import java.nio.ByteOrder;
import org.apache.mina.core.buffer.IoBuffer;
-
/**
* Represents a sequence of bytes that can be read or written directly or
* through a cursor.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public interface ByteArray extends IoAbsoluteReader, IoAbsoluteWriter
-{
+public interface ByteArray extends IoAbsoluteReader, IoAbsoluteWriter {
/**
* @inheritDoc
*/
int first();
-
/**
* @inheritDoc
*/
int last();
-
/**
* @inheritDoc
*/
ByteOrder order();
-
/**
* Set the byte order of the array.
*/
- void order( ByteOrder order );
-
+ void order(ByteOrder order);
/**
* Remove any resources associated with this object. Using the object after
@@ -64,7 +57,6 @@ public interface ByteArray extends IoAbs
*/
void free();
-
/**
* Get the sequence of <code>IoBuffer</code>s that back this array.
* Compared to <code>getSingleIoBuffer()</code>, this method should be
@@ -72,7 +64,6 @@ public interface ByteArray extends IoAbs
*/
Iterable<IoBuffer> getIoBuffers();
-
/**
* Gets a single <code>IoBuffer</code> that backs this array. Some
* implementations may initially have data split across multiple buffers, so
@@ -81,43 +72,37 @@ public interface ByteArray extends IoAbs
*/
IoBuffer getSingleIoBuffer();
-
/**
* A ByteArray is equal to another ByteArray if they start and end at the
* same index, have the same byte order, and contain the same bytes at each
* index.
*/
- public boolean equals( Object other );
-
+ public boolean equals(Object other);
/**
* @inheritDoc
*/
- byte get( int index );
-
+ byte get(int index);
/**
* @inheritDoc
*/
- public void get( int index, IoBuffer bb );
-
+ public void get(int index, IoBuffer bb);
/**
* @inheritDoc
*/
- int getInt( int index );
-
+ int getInt(int index);
/**
* Get a cursor starting at index 0 (which may not be the start of the array).
*/
Cursor cursor();
-
/**
* Get a cursor starting at the given index.
*/
- Cursor cursor( int index );
+ Cursor cursor(int index);
/**
* Provides relocatable, relative access to the underlying array. Multiple
@@ -127,45 +112,38 @@ public interface ByteArray extends IoAbs
* Should this be <code>Cloneable</code> to allow cheap mark/position
* emulation?
*/
- public interface Cursor extends IoRelativeReader, IoRelativeWriter
- {
+ public interface Cursor extends IoRelativeReader, IoRelativeWriter {
/**
* Gets the current index of the cursor.
*/
int getIndex();
-
/**
* Sets the current index of the cursor. No bounds checking will occur
* until an access occurs.
*/
- void setIndex( int index );
-
+ void setIndex(int index);
/**
* @inheritDoc
*/
int getRemaining();
-
/**
* @inheritDoc
*/
boolean hasRemaining();
-
/**
* @inheritDoc
*/
byte get();
-
/**
* @inheritDoc
*/
- void get( IoBuffer bb );
-
+ void get(IoBuffer bb);
/**
* @inheritDoc
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/ByteArrayFactory.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/ByteArrayFactory.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/ByteArrayFactory.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/ByteArrayFactory.java Sun Sep 30 23:43:23 2012
@@ -19,14 +19,12 @@
*/
package org.apache.mina.util.byteaccess;
-
/**
* A factory for <code>ByteArray</code>s.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public interface ByteArrayFactory
-{
+public interface ByteArrayFactory {
/**
* Creates an instance of {@link ByteArray} of size specified by the
* size parameter.
@@ -36,5 +34,5 @@ public interface ByteArrayFactory
* @return
* The ByteArray
*/
- ByteArray create( int size );
+ ByteArray create(int size);
}
\ No newline at end of file
Modified: mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/ByteArrayList.java
URL: http://svn.apache.org/viewvc/mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/ByteArrayList.java?rev=1392134&r1=1392133&r2=1392134&view=diff
==============================================================================
--- mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/ByteArrayList.java (original)
+++ mina/branches/2.0/mina-core/src/main/java/org/apache/mina/util/byteaccess/ByteArrayList.java Sun Sep 30 23:43:23 2012
@@ -19,17 +19,14 @@
*/
package org.apache.mina.util.byteaccess;
-
import java.util.NoSuchElementException;
-
/**
* A linked list that stores <code>ByteArray</code>s and maintains several useful invariants.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-class ByteArrayList
-{
+class ByteArrayList {
/**
* A {@link Node} which indicates the start and end of the list and does not
@@ -53,8 +50,7 @@ class ByteArrayList
* Creates a new instance of ByteArrayList.
*
*/
- protected ByteArrayList()
- {
+ protected ByteArrayList() {
header = new Node();
}
@@ -65,8 +61,7 @@ class ByteArrayList
* @return
* The last byte in the array list
*/
- public int lastByte()
- {
+ public int lastByte() {
return lastByte;
}
@@ -77,8 +72,7 @@ class ByteArrayList
* @return
* The first byte in the array list
*/
- public int firstByte()
- {
+ public int firstByte() {
return firstByte;
}
@@ -89,8 +83,7 @@ class ByteArrayList
* @return
* True if empty, otherwise false
*/
- public boolean isEmpty()
- {
+ public boolean isEmpty() {
return header.next == header;
}
@@ -100,8 +93,7 @@ class ByteArrayList
* @return
*
*/
- public Node getFirst()
- {
+ public Node getFirst() {
return header.getNextNode();
}
@@ -111,8 +103,7 @@ class ByteArrayList
* @return
* The last node in the list
*/
- public Node getLast()
- {
+ public Node getLast() {
return header.getPreviousNode();
}
@@ -123,9 +114,8 @@ class ByteArrayList
* @param ba
* The ByteArray to be added to the list
*/
- public void addFirst( ByteArray ba )
- {
- addNode( new Node( ba ), header.next );
+ public void addFirst(ByteArray ba) {
+ addNode(new Node(ba), header.next);
firstByte -= ba.last();
}
@@ -136,9 +126,8 @@ class ByteArrayList
* @param ba
* The ByteArray to be added to the list
*/
- public void addLast( ByteArray ba )
- {
- addNode( new Node( ba ), header );
+ public void addLast(ByteArray ba) {
+ addNode(new Node(ba), header);
lastByte += ba.last();
}
@@ -148,11 +137,10 @@ class ByteArrayList
* @return
* The node that was removed
*/
- public Node removeFirst()
- {
+ public Node removeFirst() {
Node node = header.getNextNode();
firstByte += node.ba.last();
- return removeNode( node );
+ return removeNode(node);
}
/**
@@ -161,14 +149,12 @@ class ByteArrayList
* @return
* The node that was taken off of the list
*/
- public Node removeLast()
- {
+ public Node removeLast() {
Node node = header.getPreviousNode();
lastByte -= node.ba.last();
- return removeNode( node );
+ return removeNode(node);
}
-
//-----------------------------------------------------------------------
/**
@@ -177,8 +163,7 @@ class ByteArrayList
* @param nodeToInsert new node to insert
* @param insertBeforeNode node to insert before
*/
- protected void addNode( Node nodeToInsert, Node insertBeforeNode )
- {
+ protected void addNode(Node nodeToInsert, Node insertBeforeNode) {
// Insert node.
nodeToInsert.next = insertBeforeNode;
nodeToInsert.previous = insertBeforeNode.previous;
@@ -186,14 +171,12 @@ class ByteArrayList
insertBeforeNode.previous = nodeToInsert;
}
-
/**
* Removes the specified node from the list.
*
* @param node the node to remove
*/
- protected Node removeNode( Node node )
- {
+ protected Node removeNode(Node node) {
// Remove node.
node.previous.next = node.next;
node.next.previous = node.previous;
@@ -208,98 +191,78 @@ class ByteArrayList
* From Commons Collections 3.1, all access to the <code>value</code> property
* is via the methods on this class.
*/
- public class Node
- {
+ public class Node {
/** A pointer to the node before this node */
private Node previous;
-
+
/** A pointer to the node after this node */
private Node next;
-
+
/** The ByteArray contained within this node */
private ByteArray ba;
-
- private boolean removed;
+ private boolean removed;
/**
* Constructs a new header node.
*/
- private Node()
- {
+ private Node() {
super();
previous = this;
next = this;
}
-
/**
* Constructs a new node with a value.
*/
- private Node( ByteArray ba )
- {
+ private Node(ByteArray ba) {
super();
-
- if ( ba == null )
- {
- throw new IllegalArgumentException( "ByteArray must not be null." );
+
+ if (ba == null) {
+ throw new IllegalArgumentException("ByteArray must not be null.");
}
-
+
this.ba = ba;
}
-
/**
* Gets the previous node.
*
* @return the previous node
*/
- public Node getPreviousNode()
- {
- if ( !hasPreviousNode() )
- {
+ public Node getPreviousNode() {
+ if (!hasPreviousNode()) {
throw new NoSuchElementException();
}
return previous;
}
-
/**
* Gets the next node.
*
* @return the next node
*/
- public Node getNextNode()
- {
- if ( !hasNextNode() )
- {
+ public Node getNextNode() {
+ if (!hasNextNode()) {
throw new NoSuchElementException();
}
return next;
}
-
- public boolean hasPreviousNode()
- {
+ public boolean hasPreviousNode() {
return previous != header;
}
-
- public boolean hasNextNode()
- {
+ public boolean hasNextNode() {
return next != header;
}
-
- public ByteArray getByteArray()
- {
+ public ByteArray getByteArray() {
return ba;
}
-
- public boolean isRemoved()
- {
+ public boolean isRemoved() {
return removed;
}
}