esoe
2 years ago
6 changed files with 43 additions and 4 deletions
@ -1,21 +1,58 @@ |
|||||||
package ru.molokoin; |
package ru.molokoin; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.io.RandomAccessFile; |
||||||
import java.nio.ByteBuffer; |
import java.nio.ByteBuffer; |
||||||
|
import java.nio.channels.FileChannel; |
||||||
import java.nio.channels.SocketChannel; |
import java.nio.channels.SocketChannel; |
||||||
|
import java.nio.file.Path; |
||||||
|
import java.nio.file.Paths; |
||||||
|
|
||||||
public class Connection { |
public class Connection { |
||||||
public SocketChannel accepted = null; |
public SocketChannel accepted = null; |
||||||
public Connection(){} |
public Connection(){} |
||||||
public Connection(SocketChannel accepted){ |
public Connection(SocketChannel accepted){ |
||||||
this.accepted = accepted; |
this.accepted = accepted; |
||||||
|
this.put(); |
||||||
} |
} |
||||||
//читаем из подключения
|
//читаем из подключения
|
||||||
public void read(ByteBuffer byteBuffer){ |
public void read(ByteBuffer byteBuffer) throws IOException{ |
||||||
//
|
//
|
||||||
|
accepted.read(byteBuffer); |
||||||
} |
} |
||||||
//пишем в подключение
|
//пишем в подключение
|
||||||
public void write(ByteBuffer byteBuffer){ |
public void write(ByteBuffer byteBuffer) throws IOException{ |
||||||
//
|
//
|
||||||
|
accepted.write(byteBuffer); |
||||||
|
} |
||||||
|
//пишем страничку по умолчанию
|
||||||
|
public void put(){ |
||||||
|
//accepted.write(null);
|
||||||
|
RandomAccessFile aFile; |
||||||
|
try { |
||||||
|
String stringPath = "src/main/webapp/upload.http"; |
||||||
|
Path path = Paths.get(stringPath); |
||||||
|
aFile = new RandomAccessFile(path.toAbsolutePath().toString(), "rw"); |
||||||
|
FileChannel inChannel = aFile.getChannel(); |
||||||
|
ByteBuffer buf = ByteBuffer.allocate(24); |
||||||
|
int bytesRead; |
||||||
|
bytesRead = inChannel.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 = inChannel.read(buf); |
||||||
|
} |
||||||
|
aFile.close(); |
||||||
|
} |
||||||
|
catch (IOException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue