本文整理汇总了Java中org.bukkit.util.io.BukkitObjectOutputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java BukkitObjectOutputStream.close方法的具体用法?Java BukkitObjectOutputStream.close怎么用?Java BukkitObjectOutputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.util.io.BukkitObjectOutputStream
的用法示例。
在下文中一共展示了BukkitObjectOutputStream.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: itemStackArrayToBase64
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
/**
*
* A method to serialize an {@link ItemStack} array to Base64 String.
*
* <p />
*
* Based off of {@link #toBase64(Inventory)}.
*
* @param items to turn into a Base64 String.
* @return Base64 string of the items.
* @throws IllegalStateException
*/
public static String itemStackArrayToBase64(ItemStack[] items) throws IllegalStateException {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
// Write the size of the inventory
dataOutput.writeInt(items.length);
// Save every element in the list
for (int i = 0; i < items.length; i++) {
dataOutput.writeObject(items[i]);
}
// Serialize that array
dataOutput.close();
return Base64Coder.encodeLines(outputStream.toByteArray());
} catch (Exception e) {
throw new IllegalStateException("Unable to save item stacks.", e);
}
}
示例2: toBase64
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
/**
* A method to serialize an inventory to Base64 string.
*
* <p />
*
* Special thanks to Comphenix in the Bukkit forums or also known
* as aadnk on GitHub.
*
* <a href="https://gist.github.com/aadnk/8138186">Original Source</a>
*
* @param inventory to serialize
* @return Base64 string of the provided inventory
* @throws IllegalStateException
*/
public static String toBase64(Inventory inventory) throws IllegalStateException {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
dataOutput.writeInt(inventory.getSize());
for (int i = 0; i < inventory.getSize(); i++) {
dataOutput.writeObject(inventory.getItem(i));
}
dataOutput.close();
return Base64Coder.encodeLines(outputStream.toByteArray());
} catch (Exception e) {
throw new IllegalStateException("Unable to save item stacks.", e);
}
}
示例3: itemStackArrayToBase64
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
/**
*
* @param items
* @return A base64 encoded String
* @throws IllegalStateException
*
* It encodes an {@link ItemStack} array to a base64 String
*/
public static String itemStackArrayToBase64(ItemStack[] items) throws IllegalStateException
{
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
dataOutput.writeInt(items.length);
for (int i = 0; i < items.length; i++) {
dataOutput.writeObject(items[i]);
}
dataOutput.close();
return Base64Coder.encodeLines(outputStream.toByteArray());
} catch (Exception e) {
throw new IllegalStateException("Unable to save item stacks.", e);
}
}
示例4: itemStackArrayToBase64
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
public static String itemStackArrayToBase64(ItemStack[] items) throws IllegalStateException {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
// Write the size of the inventory
dataOutput.writeInt(items.length);
// Save every element in the list
for (int i = 0; i < items.length; i++) {
dataOutput.writeObject(items[i]);
}
// Serialize that array
dataOutput.close();
return Base64Coder.encodeLines(outputStream.toByteArray());
} catch (Exception e) {
throw new IllegalStateException("Unable to save item stacks.", e);
}
}
示例5: toBase64
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
public static String toBase64(Inventory inventory) throws IllegalStateException {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
// Write the size of the inventory
dataOutput.writeInt(inventory.getSize());
// Save every element in the list
for (int i = 0; i < inventory.getSize(); i++) {
dataOutput.writeObject(inventory.getItem(i));
}
// Serialize that array
dataOutput.close();
return Base64Coder.encodeLines(outputStream.toByteArray());
} catch (Exception e) {
throw new IllegalStateException("Unable to save item stacks.", e);
}
}
示例6: serializeItemStack
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
public static String serializeItemStack(ItemStack inv) {
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
BukkitObjectOutputStream bos = new BukkitObjectOutputStream(os);
bos.writeObject(inv);
String hex = BukkitObjectUtil.byteArrayToHexString(os.toByteArray());
bos.close();
os.close();
return hex;
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}
示例7: serializeItemStacks
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
public static String serializeItemStacks(ItemStack[] inv) {
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
BukkitObjectOutputStream bos = new BukkitObjectOutputStream(os);
bos.writeObject(inv);
String hex = BukkitObjectUtil.byteArrayToHexString(os.toByteArray());
bos.close();
os.close();
return hex;
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}
示例8: serializePotionEffects
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
public static String serializePotionEffects(Collection<PotionEffect> effects) {
PotionEffect[] eff = new PotionEffect[effects.size()];
int count = 0;
for (PotionEffect effect : effects) {
eff[count] = effect;
count++;
}
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
BukkitObjectOutputStream bos = new BukkitObjectOutputStream(os);
bos.writeObject(eff);
String hex = BukkitObjectUtil.byteArrayToHexString(os.toByteArray());
bos.close();
os.close();
return hex;
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}
示例9: toBase64
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
public static String toBase64(Inventory inventory) {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
// Write the size of the inventory
dataOutput.writeInt(inventory.getSize());
// Save every element in the list
for (int i = 0; i < inventory.getSize(); i++) {
dataOutput.writeObject(inventory.getItem(i));
}
// Serialize that array
dataOutput.close();
return Base64Coder.encodeLines(outputStream.toByteArray());
} catch (Exception e) {
throw new IllegalStateException("Unable to save item stacks.", e);
}
}
示例10: save
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
public void save(NBTCompoundTag rootTag) throws IOException
{
rootTag.setTag("X", new NBTShortTag((short)(location.getBlockX() - location.getChunk().getX() * 16)));
rootTag.setTag("Y", new NBTShortTag((short)location.getBlockY()));
rootTag.setTag("Z", new NBTShortTag((short)(location.getBlockZ() - location.getChunk().getZ() * 16)));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BukkitObjectOutputStream boos = new BukkitObjectOutputStream(baos);
boos.writeObject( items );
rootTag.setTag("BukkitItemStackArray", new NBTByteArrayTag(baos.toByteArray()));
boos.close();
rootTag.setTag("InventoryType", new NBTStringTag(invType.name()));
}
示例11: inventoryToString
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
/**
* Transfer a inventory into a string
*
* @param inventory Inventory
* @return String
*/
@Deprecated
public static String inventoryToString(Inventory inventory) {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
// Write the size of the inventory
dataOutput.writeInt(inventory.getSize());
// Save every element in the list
for (int i = 0; i < inventory.getSize(); i++) {
dataOutput.writeObject(inventory.getItem(i));
}
// Serialize that array
dataOutput.close();
return Base64Coder.encodeLines(outputStream.toByteArray());
} catch (Exception e) {
throw new IllegalStateException("Unable to save item stacks.", e);
}
}
示例12: toBase64
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
public static String toBase64(Inventory inventory) {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
// Write the size of the inventory
dataOutput.writeInt(inventory.getSize());
// Save every element in the list
for (int i = 0; i < inventory.getSize(); i++) {
dataOutput.writeObject(inventory.getItem(i));
}
// Serialize that array
dataOutput.close();
return Base64Coder.encodeLines(outputStream.toByteArray());
} catch (Exception e) {
throw new IllegalStateException("Cannot into itemstacksz!", e);
}
}
示例13: itemStackArrayToBase64
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
/**
*
* A method to serialize an {@link ItemStack} array to Base64 String.
*
* <p>
*
* Based off of {@link #toBase64(Inventory)}.
*
* @param items to turn into a Base64 String.
* @return Base64 string of the items.
* @throws IllegalStateException if any of the {@link ItemStack}s couldn't be parsed
*/
public static String itemStackArrayToBase64(ItemStack[] items) throws IllegalStateException {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
// Write the size of the inventory
dataOutput.writeInt(items.length);
// Save every element in the list
for (ItemStack item : items) {
dataOutput.writeObject(item);
}
// Serialize that array
dataOutput.close();
return Base64Coder.encodeLines(outputStream.toByteArray());
} catch (Exception e) {
throw new IllegalStateException("Unable to save item stacks.", e);
}
}
示例14: toBase64
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
/**
* A method to serialize an inventory to Base64 string.
*
* <p>
*
* Special thanks to Comphenix in the Bukkit forums or also known
* as aadnk on GitHub. <a href="https://gist.github.com/aadnk/8138186">Original Source</a>
*
* @param inventory to serialize
* @return Base64 string of the provided inventory
* @throws IllegalStateException if any of the {@link ItemStack}s couldn't be parsed
*/
public static String toBase64(Inventory inventory) throws IllegalStateException {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
// Write the size of the inventory
dataOutput.writeInt(inventory.getSize());
// Save every element in the list
for (int i = 0; i < inventory.getSize(); i++) {
dataOutput.writeObject(inventory.getItem(i));
}
// Serialize that array
dataOutput.close();
return Base64Coder.encodeLines(outputStream.toByteArray());
} catch (Exception e) {
throw new IllegalStateException("Unable to save item stacks.", e);
}
}
示例15: saveEnderchest
import org.bukkit.util.io.BukkitObjectOutputStream; //导入方法依赖的package包/类
private void saveEnderchest(Inventory inv) {
Map<String, Object> enderchest = new HashMap<String, Object>();
for(int slot = 0; slot < inv.getSize(); slot++) {
ItemStack item = inv.getItem(slot);
if(item != null) {
enderchest.put(String.valueOf(slot), inv.getItem(slot).serialize());
}
}
try {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
BukkitObjectOutputStream out = new BukkitObjectOutputStream(byteOut);
out.writeObject(enderchest);
out.close();
this.database.setValue(this.key + ".enderchest", byteOut.toByteArray());
} catch(Exception e) {
this.module.getLogger().log(Level.SEVERE, "Failed to save enderchest.", e);
}
}