diff --git a/src/main/java/ru/molokoin/Connection.java b/src/main/java/ru/molokoin/Connection.java index 2c832ac..f0b7e66 100644 --- a/src/main/java/ru/molokoin/Connection.java +++ b/src/main/java/ru/molokoin/Connection.java @@ -11,17 +11,26 @@ import java.nio.file.Paths; public class Connection { public SocketChannel accepted = null; - + public Connection(){} public Connection(SocketChannel accepted){ this.accepted = accepted; write(); read(); } - //читаем из подключения + // + /** + * читаем из подключения, получаем запрос пользователя ... + * + * нужно разобрать запрос: + * - отделить тело запроса от заголовка + * - прочитать заголовок, вытащить тип запроса (get/post) и наименование запрашиваемого ресурса + * - если запрос типа POST, сохранить тело запроса в новый файл и направить позователю страничку uploads + * - если запрос типа GET, направить пользователю страничку uploads + */ public void read(){ try{ - //RandomAccessFile aFile; + //RandomAccessFile uploadedFile; ByteBuffer buf = ByteBuffer.allocate(1024); int bytesRead = accepted.read(buf); while (bytesRead != -1){ @@ -41,15 +50,15 @@ public class Connection { e.printStackTrace(); } } - //пишем в подключение из файла + //пишем в подключение из файла - ответ сервера public void write(){ //accepted.write(null); - RandomAccessFile aFile; + RandomAccessFile responseFile; try { String stringPath = "src/main/webapp/upload.http"; Path path = Paths.get(stringPath); - aFile = new RandomAccessFile(path.toAbsolutePath().toString(), "rw"); - FileChannel inChannel = aFile.getChannel(); + responseFile = new RandomAccessFile(path.toAbsolutePath().toString(), "rw"); + FileChannel inChannel = responseFile.getChannel(); ByteBuffer buf = ByteBuffer.allocate(1024); int bytesRead; bytesRead = inChannel.read(buf); @@ -64,7 +73,7 @@ public class Connection { buf.clear(); bytesRead = inChannel.read(buf); } - aFile.close(); + responseFile.close(); } catch (IOException e) { e.printStackTrace(); diff --git a/target/classes/ru/molokoin/Connection.class b/target/classes/ru/molokoin/Connection.class index d772a14..a2f9191 100644 Binary files a/target/classes/ru/molokoin/Connection.class and b/target/classes/ru/molokoin/Connection.class differ