esoe 2 years ago
parent
commit
1afa15cb4b
  1. 23
      src/main/java/ru/molokoin/Connection.java
  2. BIN
      target/classes/ru/molokoin/Connection.class

23
src/main/java/ru/molokoin/Connection.java

@ -18,10 +18,19 @@ public class Connection {
write(); write();
read(); read();
} }
//читаем из подключения //
/**
* читаем из подключения, получаем запрос пользователя ...
*
* нужно разобрать запрос:
* - отделить тело запроса от заголовка
* - прочитать заголовок, вытащить тип запроса (get/post) и наименование запрашиваемого ресурса
* - если запрос типа POST, сохранить тело запроса в новый файл и направить позователю страничку uploads
* - если запрос типа GET, направить пользователю страничку uploads
*/
public void read(){ public void read(){
try{ try{
//RandomAccessFile aFile; //RandomAccessFile uploadedFile;
ByteBuffer buf = ByteBuffer.allocate(1024); ByteBuffer buf = ByteBuffer.allocate(1024);
int bytesRead = accepted.read(buf); int bytesRead = accepted.read(buf);
while (bytesRead != -1){ while (bytesRead != -1){
@ -41,15 +50,15 @@ public class Connection {
e.printStackTrace(); e.printStackTrace();
} }
} }
//пишем в подключение из файла //пишем в подключение из файла - ответ сервера
public void write(){ public void write(){
//accepted.write(null); //accepted.write(null);
RandomAccessFile aFile; RandomAccessFile responseFile;
try { try {
String stringPath = "src/main/webapp/upload.http"; String stringPath = "src/main/webapp/upload.http";
Path path = Paths.get(stringPath); Path path = Paths.get(stringPath);
aFile = new RandomAccessFile(path.toAbsolutePath().toString(), "rw"); responseFile = new RandomAccessFile(path.toAbsolutePath().toString(), "rw");
FileChannel inChannel = aFile.getChannel(); FileChannel inChannel = responseFile.getChannel();
ByteBuffer buf = ByteBuffer.allocate(1024); ByteBuffer buf = ByteBuffer.allocate(1024);
int bytesRead; int bytesRead;
bytesRead = inChannel.read(buf); bytesRead = inChannel.read(buf);
@ -64,7 +73,7 @@ public class Connection {
buf.clear(); buf.clear();
bytesRead = inChannel.read(buf); bytesRead = inChannel.read(buf);
} }
aFile.close(); responseFile.close();
} }
catch (IOException e) { catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

BIN
target/classes/ru/molokoin/Connection.class

Binary file not shown.
Loading…
Cancel
Save