Java tutorial
/* * Copyright (c) 2016 "JackWhite20" * * This file is part of HFTP. * * HFTP is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.jackwhite20.hftp.shared.packet; import de.jackwhite20.cascade.shared.protocol.packet.Packet; import de.jackwhite20.cascade.shared.protocol.packet.PacketInfo; import de.jackwhite20.hftp.shared.file.ListFileData; import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.List; /** * Created by JackWhite20 on 25.09.2016. */ @PacketInfo(2) public class ListDirectoryPacket extends Packet { private List<ListFileData> listFileData = new ArrayList<>(); public ListDirectoryPacket() { } public ListDirectoryPacket(List<ListFileData> listFileData) { this.listFileData = listFileData; } @Override public void read(ByteBuf byteBuf) throws Exception { int size = byteBuf.readInt(); for (int i = 0; i < size; i++) { listFileData.add(new ListFileData(readString(byteBuf), byteBuf.readFloat(), readString(byteBuf), byteBuf.readBoolean())); } } @Override public void write(ByteBuf byteBuf) throws Exception { byteBuf.writeInt(listFileData.size()); for (ListFileData data : listFileData) { writeString(byteBuf, data.getName()); byteBuf.writeFloat(data.getSize()); writeString(byteBuf, data.getHash()); byteBuf.writeBoolean(data.isDirectory()); } } public List<ListFileData> getListFileData() { return listFileData; } }