こんにちは、以下のコードに問題があります。try および catch ブロックの IDE の try 行に赤い X が表示され、"(" が検出されましたが、"{" が予期されていたことが示されています。
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.StandardSocketOptions;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
/** * * @author Apress */
public class FutureForm
{
public static void main(String[] args)
{
final int DEFAULT_PORT = 5555;
final String IP = "127.0.0.1";
// v-This parenthesis should be a bracket it says??
try( AsynchronousServerSocketChannel asynchronousServerSocketChannel = AsynchronousServerSocketChannel.open())
{
if (asynchronousServerSocketChannel.isOpen())
{
asynchronousServerSocketChannel.bind(new InetSocketAddress(IP, DEFAULT_PORT));
System.out.println("Waiting for connections ...");
while (true)
{
Future<AsynchronousSocketChannel> asynchronousSocketChannelFuture = asynchronousServerSocketChannel.accept();
try (AsynchronousSocketChannel asynchronousSocketChannel = asynchronousSocketChannelFuture.get())
{
System.out.println("Incoming connection from: " + asynchronousSocketChannel.getRemoteAddress());
final ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
while (asynchronousSocketChannel.read(buffer).get() != -1)
{
buffer.flip();
asynchronousSocketChannel.write(buffer).get();
if (buffer.hasRemaining())
buffer.compact();
else
buffer.clear();
}
System.out.println(asynchronousSocketChannel.getRemoteAddress() + " was successfully served!");
}
catch (IOException || InterruptedException || ExecutionException ex)
{
System.err.println(ex);
}
}
}
else
{
System.out.println("The asynchronous server-socket channel cannot be opened!");
}
}
catch (IOException ex)
{
System.err.println(ex);
}
}
}