本文整理汇总了Java中com.badlogic.gdx.utils.Base64Coder.decode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64Coder.decode方法的具体用法?Java Base64Coder.decode怎么用?Java Base64Coder.decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.utils.Base64Coder
的用法示例。
在下文中一共展示了Base64Coder.decode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMessage
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
@Override
public void onMessage(WebSocket conn, String message) {
try {
KryoConnection k = getBySocket(conn);
if (k == null) return;
if(message.equals("_ping_")){
conn.send(connections.size() + "|" + Vars.player.name);
connections.remove(k);
}else {
if (debug) UCore.log("Got message: " + message);
byte[] out = Base64Coder.decode(message);
if (debug) UCore.log("Decoded: " + Arrays.toString(out));
ByteBuffer buffer = ByteBuffer.wrap(out);
Object o = serializer.read(buffer);
Net.handleServerReceived(o, k.id);
}
}catch (Exception e){
UCore.log("Error reading message!");
e.printStackTrace();
}
}
示例2: loadFromSlot
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
public static void loadFromSlot(int slot){
if(Vars.gwt){
String string = Settings.getString("save-"+slot+"-data");
ByteArrayInputStream stream = new ByteArrayInputStream(Base64Coder.decode(string));
load(stream);
}else{
load(fileFor(slot));
}
}
示例3: readSlotMeta
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
public static DataInputStream readSlotMeta(int slot){
if(Vars.gwt){
String string = Settings.getString("save-"+slot+"-data");
byte[] bytes = Base64Coder.decode(string);
return new DataInputStream(new ByteArrayInputStream(bytes));
}else{
return new DataInputStream(fileFor(slot).read());
}
}
示例4: processLayerDataXML
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
private void processLayerDataXML(final Element layerNode, final int width, final int height)
throws IOException {
final String data = layerNode.getChildNodes().item(1).getTextContent().trim();
final byte[] decodedBytes = Base64Coder.decode(data);
final GZIPInputStream stream = new GZIPInputStream(new ByteArrayInputStream(decodedBytes));
final int[] _tileData = new int[width * height];
int pos = 0;
while (pos < (width * height)) {
int tileNum = stream.read(); tileNum |= (stream.read() << 8);
tileNum |= (stream.read() << 16); tileNum |= (stream.read() << 24);
_tileData[pos++] = tileNum - 1;
}
_stageFactory.generate().setTileData(_tileData);
}
示例5: connect
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
@Override
public void connect(String ip, int port) throws IOException {
try {
URI i = new URI("ws://" + ip + ":" + Vars.webPort);
UCore.log("Connecting: " + i);
socket = new WebSocketClient(i, new Draft_6455(), null, 5000) {
Thread thread;
@Override
public void connect() {
if(thread != null )
throw new IllegalStateException( "WebSocketClient objects are not reuseable" );
thread = new Thread(this);
thread.setDaemon(true);
thread.start();
}
@Override
public void onOpen(ServerHandshake handshakedata) {
UCore.log("Connected!");
Connect connect = new Connect();
Net.handleClientReceived(connect);
}
@Override
public void onMessage(String message) {
if(debug) UCore.log("Got message: " + message);
try {
byte[] bytes = Base64Coder.decode(message);
ByteBuffer buffer = ByteBuffer.wrap(bytes);
byte id = buffer.get();
if (id == -2) {
//this is a framework message... do nothing yet?
} else {
Class<?> type = Registrator.getByID(id);
if(debug) UCore.log("Got class ID: " + type);
Packet packet = (Packet) ClassReflection.newInstance(type);
packet.read(buffer);
Net.handleClientReceived(packet);
}
} catch (Exception e) {
e.printStackTrace();
//throw new RuntimeException(e);
}
}
@Override
public void onClose(int code, String reason, boolean remote) {
if(debug) UCore.log("Closed.");
Disconnect disconnect = new Disconnect();
Net.handleClientReceived(disconnect);
}
@Override
public void onError(Exception ex) {
onClose(0, null, true);
ex.printStackTrace();
}
};
socket.connect();
}catch (URISyntaxException e){
throw new IOException(e);
}
}
示例6: getTileIds
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
static public int[] getTileIds (Element element, int width, int height) {
Element data = element.getChildByName("data");
String encoding = data.getAttribute("encoding", null);
if (encoding == null) { // no 'encoding' attribute means that the encoding is XML
throw new GdxRuntimeException("Unsupported encoding (XML) for TMX Layer Data");
}
int[] ids = new int[width * height];
if (encoding.equals("csv")) {
String[] array = data.getText().split(",");
for (int i = 0; i < array.length; i++)
ids[i] = (int)Long.parseLong(array[i].trim());
} else {
if (true)
if (encoding.equals("base64")) {
InputStream is = null;
try {
String compression = data.getAttribute("compression", null);
byte[] bytes = Base64Coder.decode(data.getText());
if (compression == null)
is = new ByteArrayInputStream(bytes);
else if (compression.equals("gzip"))
is = new GZIPInputStream(new ByteArrayInputStream(bytes), bytes.length);
else if (compression.equals("zlib"))
is = new InflaterInputStream(new ByteArrayInputStream(bytes));
else
throw new GdxRuntimeException("Unrecognised compression (" + compression + ") for TMX Layer Data");
byte[] temp = new byte[4];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int read = is.read(temp);
while (read < temp.length) {
int curr = is.read(temp, read, temp.length - read);
if (curr == -1) break;
read += curr;
}
if (read != temp.length)
throw new GdxRuntimeException("Error Reading TMX Layer Data: Premature end of tile data");
ids[y * width + x] = unsignedByteToInt(temp[0]) | unsignedByteToInt(temp[1]) << 8
| unsignedByteToInt(temp[2]) << 16 | unsignedByteToInt(temp[3]) << 24;
}
}
} catch (IOException e) {
throw new GdxRuntimeException("Error Reading TMX Layer Data - IOException: " + e.getMessage());
} finally {
StreamUtils.closeQuietly(is);
}
} else {
// any other value of 'encoding' is one we're not aware of, probably a feature of a future version of Tiled
// or another editor
throw new GdxRuntimeException("Unrecognised encoding (" + encoding + ") for TMX Layer Data");
}
}
return ids;
}
示例7: decode
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
public byte[] decode(String src) {
return Base64Coder.decode(src);
}
示例8: create
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
public static TilePrefab create(FileHandle file, JsonTilePrefab definition, AssetManager assetManager) {
if (Strings.isNullOrEmpty(definition.data))
throw new AssetLoadingException(file.path(), "No tile data.");
TilePrefab prefab = new TilePrefab(definition.width, definition.height, definition.depth);
byte[] dataBytes = Base64Coder.decode(definition.data);
ByteBuffer buffer = ByteBuffer.wrap(dataBytes);
TileDataSerializer.deserialize(buffer, prefab);
return prefab;
}