private CompoundMap createCompoundFromServer(ServerInfo server){ CompoundMap result = new CompoundMap(); result.put("name", new StringTag("name", server.getName())); String ipString = server.getIP(); if(server.getPort() != DEFAULT_PORT) ipString = ipString.concat(":".concat(Integer.toString(server.getPort()))); result.put("ip", new StringTag("ip", ipString)); if(server.hasIcon()) result.put("icon", new StringTag("icon", server.getIcon())); return result; }
/** * Writes a {@code TAG_String} tag. * * @param tag The tag. * @throws java.io.IOException if an I/O error occurs. */ private void writeStringTagPayload(StringTag tag) throws IOException { byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET.name()); os.writeShort(bytes.length); os.write(bytes); }
@Before public void setUp() { subject = new ExampleHolder(); CompoundMap map = new CompoundMap(); map.put(new StringTag("name", "helloworld")); CompoundTag mapTag = new CompoundTag("", map); subject.load(mapTag); }
/** * Writes a {@code TAG_String} tag. * * @param tag The tag. * @throws java.io.IOException if an I/O error occurs. */ private void writeStringTagPayload(StringTag tag) throws IOException { byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET.name()); os.writeShort(bytes.length); os.write(bytes); }
bytes = new byte[length]; is.readFully(bytes); return new StringTag(name, new String(bytes, NBTConstants.CHARSET.name()));
/** * Writes a {@code TAG_String} tag. * * @param tag The tag. * @throws java.io.IOException if an I/O error occurs. */ private void writeStringTagPayload(StringTag tag) throws IOException { byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET.name()); os.writeShort(bytes.length); os.write(bytes); }
bytes = new byte[length]; is.readFully(bytes); return new StringTag(name, new String(bytes, NBTConstants.CHARSET.name()));
private static ServerInfo createServerFromTag(CompoundMap compound){ String ipString, ip, name, icon = null; int port; ipString = compound.get("ip").getValue().toString(); name = compound.get("name").getValue().toString(); if(ipString.contains(":")){ ip = ipString.split(":")[0]; port = Integer.parseInt(ipString.split(":")[1]); } else { ip = ipString; port = DEFAULT_PORT; } if(compound.containsKey("icon")){ icon = ((StringTag)compound.get("icon")).getValue(); } return new ServerInfo(ip, name, icon,port); }
bytes = new byte[length]; is.readFully(bytes); return new StringTag(name, new String(bytes, NBTConstants.CHARSET.name()));