本文整理汇总了Java中com.badlogic.gdx.utils.Base64Coder.encode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64Coder.encode方法的具体用法?Java Base64Coder.encode怎么用?Java Base64Coder.encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.utils.Base64Coder
的用法示例。
在下文中一共展示了Base64Coder.encode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
public static void save(TilePrefab prefab, String outputFilename) {
if (prefab == null)
throw new IllegalArgumentException();
JsonTilePrefab jsonPrefab = new JsonTilePrefab();
jsonPrefab.width = prefab.getWidth();
jsonPrefab.height = prefab.getHeight();
jsonPrefab.depth = prefab.getDepth();
byte[] dataBytes = new byte[prefab.getData().length * TileDataSerializer.TILE_SIZE_BYTES];
ByteBuffer buffer = ByteBuffer.wrap(dataBytes);
TileDataSerializer.serialize(prefab, buffer);
jsonPrefab.data = new String(Base64Coder.encode(dataBytes));
Json json = new Json();
String output = json.prettyPrint(jsonPrefab);
FileHandle outputFile = Gdx.files.local(outputFilename);
outputFile.writeString(output, false);
}
示例2: send
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
@Override
public void send(Object object, SendMode mode) {
if(!(object instanceof Packet)) throw new RuntimeException("All sent objects must be packets!");
Packet p = (Packet)object;
buffer.position(0);
buffer.put(Registrator.getID(object.getClass()));
p.write(buffer);
int pos = buffer.position();
buffer.position(0);
byte[] out = new byte[pos];
buffer.get(out);
String string = new String(Base64Coder.encode(out));
if(debug) UCore.log("Sending string: " + string);
socket.send(string);
}
示例3: send
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
@Override
public void send(Object object, SendMode mode){
if(socket != null){
try {
synchronized (buffer) {
buffer.position(0);
if(debug) UCore.log("Sending object with ID " + Registrator.getID(object.getClass()));
serializer.write(buffer, object);
int pos = buffer.position();
buffer.position(0);
byte[] out = new byte[pos];
buffer.get(out);
String string = new String(Base64Coder.encode(out));
if(debug) UCore.log("Sending string: " + string);
socket.send(string);
}
}catch (Exception e){
e.printStackTrace();
connections.remove(this);
}
}else if (connection != null) {
if (mode == SendMode.tcp) {
connection.sendTCP(object);
} else {
connection.sendUDP(object);
}
}
}
示例4: send
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
@Override
public void send(Object object, SendMode mode) {
if(!(object instanceof Packet)) throw new RuntimeException("All sent objects must be packets!");
Packet p = (Packet)object;
buffer.position(0);
buffer.put(Registrator.getID(object.getClass()));
p.write(buffer);
int pos = buffer.position();
buffer.position(0);
byte[] out = new byte[pos];
buffer.get(out);
String string = new String(Base64Coder.encode(out));
socket.send(string);
}
示例5: createTextureFromBytes
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
/**
* Creates texture region from byte[].
* <p>
* GWT platform requires additional step (as far as i know) to deal with Pixmap. It is need to load Image element
* and wait until it is loaded.
*
* @param bytes Image byte[] representation, not null
* @param consumer Consumer where you should deal with region, not null
*/
public static void createTextureFromBytes(byte[] bytes, final Consumer<TextureRegion> consumer)
{
String base64 = "data:image/png;base64," + new String(Base64Coder.encode(bytes));
final Image image = new Image();
image.setVisible(false);
image.addLoadHandler(new LoadHandler()
{
@Override
public void onLoad(LoadEvent event)
{
ImageElement imageElement = image.getElement().cast();
Pixmap pixmap = new Pixmap(imageElement);
Gdx.app.log("ImageHelper", "pixmap: " + pixmap.getWidth() + "/" + pixmap.getHeight());
final int orgWidth = pixmap.getWidth();
final int orgHeight = pixmap.getHeight();
int width = MathUtils.nextPowerOfTwo(orgWidth);
int height = MathUtils.nextPowerOfTwo(orgHeight);
final Pixmap potPixmap = new Pixmap(width, height, pixmap.getFormat());
potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight());
pixmap.dispose();
TextureRegion region = new TextureRegion(new Texture(potPixmap), 0, 0, orgWidth, orgHeight);
potPixmap.dispose();
RootPanel.get().remove(image);
consumer.accept(region);
}
});
image.setUrl(base64);
RootPanel.get().add(image);
}
示例6: encrypt
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
public static String encrypt(String input, String key){
byte[] crypted = null;
try{
SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skey);
crypted = cipher.doFinal(input.getBytes());
}catch(Exception e){
System.out.println(e.toString());
}
return new String(Base64Coder.encode(crypted));
}
示例7: encode
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
public static String encode(byte[] signature) {
return new String(Base64Coder.encode(signature));
}
示例8: encode
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
public byte[] encode(byte[] src) {
char[] base64 = Base64Coder.encode(src);
String str = new String(base64);
return str.getBytes();
}
示例9: encodeToString
import com.badlogic.gdx.utils.Base64Coder; //导入方法依赖的package包/类
public String encodeToString(byte[] src) {
char[] base64 = Base64Coder.encode(src);
return new String(base64);
}