@ -13,20 +13,32 @@ public class Connection {
@@ -13,20 +13,32 @@ public class Connection {
public Connection ( ) { }
public Connection ( SocketChannel accepted ) {
this . accepted = accepted ;
this . put ( ) ;
this . write ( ) ;
this . read ( ) ;
}
//читаем из подключения
public void read ( ByteBuffer byteBuffer ) throws IOException {
//
accepted . read ( byteBuffer ) ;
public void read ( ) {
try {
RandomAccessFile aFile ;
ByteBuffer buf = ByteBuffer . allocate ( 1024 ) ;
int bytesRead = accepted . read ( buf ) ;
while ( bytesRead ! = - 1 ) {
System . out . println ( "Read " + bytesRead ) ;
buf . flip ( ) ;
while ( buf . hasRemaining ( ) ) {
System . out . print ( ( char ) buf . get ( ) ) ;
//accepted.write(buf);
}
buf . clear ( ) ;
bytesRead = accepted . read ( buf ) ;
}
}
catch ( IOException e ) {
e . printStackTrace ( ) ;
}
}
//пишем в подключение
public void write ( ByteBuffer byteBuffer ) throws IOException {
//
accepted . write ( byteBuffer ) ;
}
//пишем страничку по умолчанию
public void put ( ) {
public void write ( ) {
//accepted.write(null);
RandomAccessFile aFile ;
try {
@ -34,11 +46,11 @@ public class Connection {
@@ -34,11 +46,11 @@ public class Connection {
Path path = Paths . get ( stringPath ) ;
aFile = new RandomAccessFile ( path . toAbsolutePath ( ) . toString ( ) , "rw" ) ;
FileChannel inChannel = aFile . getChannel ( ) ;
ByteBuffer buf = ByteBuffer . allocate ( 24 ) ;
ByteBuffer buf = ByteBuffer . allocate ( 10 24) ;
int bytesRead ;
bytesRead = inChannel . read ( buf ) ;
while ( bytesRead ! = - 1 ) {
System . out . println ( "Read " + bytesRead ) ;
System . out . println ( "Write " + bytesRead ) ;
buf . flip ( ) ;
while ( buf . hasRemaining ( ) ) {
//System.out.print((char) buf.get());
@ -52,7 +64,5 @@ public class Connection {
@@ -52,7 +64,5 @@ public class Connection {
catch ( IOException e ) {
e . printStackTrace ( ) ;
}
}
}