Skip to content

Conversation

@nizshee
Copy link
Owner

@nizshee nizshee commented Oct 14, 2016

Copy link

@sproshev sproshev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

надо исправлять

System.out.print(b);
}
System.out.println();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а если аргументы неверные? тихонько выйдем и ничего не скажем?)

System.out.println(bytes.length);
for (byte b: bytes) {
System.out.print(b);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. файл может не влезть в память -1
  2. бинарные файлы тоже в консоль будут выводиться? может все-таки сохранить?

DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
DataInputStream dis = new DataInputStream(socket.getInputStream());
dos.writeInt(code);
method.writeValue(dos, value);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

странно, почему разные сущности что-то пишут в dos? почему value дается снаружи, а пишет его method? может лучше method все запишет и все прочитает?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method - удаленная процедура. Она знает как сериализовывать/десериализовывать объекты.
Это разумно. С другой стороны она не знает какой у нее идентификатор на конкретном сервере, что тоже, вроде, разумно.

DataInputStream dis = new DataInputStream(socket.getInputStream());
dos.writeInt(code);
method.writeValue(dos, value);
return method.readResult(dis);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сокет не закрывается -1

return getValue(new Socket(host, port), 2, new GetMethod(), name);
}

public static <Value, Result> Result getValue(Socket socket, int code, Method<Value, Result> method, Value value)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

используется только внутри класса и тестах, это значит, что:

должен стать приватным
тесты должны быть написаны без него

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Изначальная задумка была в том, чтобы разнести межсетевое взаимодействие и работу с данными, и тестировать их раздельно. Этот метод способствует задумки. Я перенес его в интерфейс Method.

void writeResult(DataOutputStream dos, Result result) throws IOException;

Result readResult(DataInputStream dis) throws IOException;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

еще и названия сбивают с толку, как понять, что делает apply? может лучше его сигнатуру заменить на Result execute(Request request)?

то же и с write/readvalue

dos.write(bytes, 0, bytes.length);
for (Byte aByte : bytes) {
dos.writeByte(aByte);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

файл два раза пишется? -0.5


@Override
public byte[] readResult(DataInputStream dis) throws IOException {
int length = dis.readInt();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по заданию -- лонг

int length = dis.readInt();
byte[] bytes = new byte[length];
int read = dis.read(bytes, 0, length);
if (read != length) throw new IOException("Bad read,");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??? вполне естественная ситуация, надо ее поддерживать -1. см readFully у dis


@Override
public String toString() {
return name;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а как пользователю увидеть папка это или файл? -0.25

@nizshee
Copy link
Owner Author

nizshee commented Nov 15, 2016

Я слегка просчитался. Идея класса Method была в том, чтобы передавать небольшие объекты.
Для get пришлось добавить абстракцию над операцией на сервере, и в Client написать напрямую работу с байтами.

@nizshee
Copy link
Owner Author

nizshee commented Jan 11, 2017

Я на всякий случай напишу, что готово к проверке.

Copy link

@sproshev sproshev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6.25

import java.net.Socket;
import java.util.List;

@SuppressWarnings("all")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше подавлять конкретные варнинги и как можно ближе к месту подавления, иначе какой-н. важный варнинг в будущем будет подавлен

try (Socket socket = new Socket(host, port)) {
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
dos.writeInt(2);
dos.writeUTF(name);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flush

import java.io.IOException;
import java.net.Socket;

public interface Method<Request, Response> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по сути выродился в ListMethod

dos.writeInt(code);
method.writeRequest(dos, request);
Response response = method.readResult(dis);
socket.close();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

до этого места не всегда дойдет


private final static int code = 0;
private final static AtomicBoolean trigger = new AtomicBoolean(false);
public static final Method<String, String> method = new Method<String, String>() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caps

Server server = new Server(InetAddress.getByName("localhost"), 8080);
server.start(handlers);
Thread.sleep(500);
Client client = new Client("localhost", 8080);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не используется

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants