本文整理汇总了Java中com.badlogic.gdx.utils.StreamUtils类的典型用法代码示例。如果您正苦于以下问题:Java StreamUtils类的具体用法?Java StreamUtils怎么用?Java StreamUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StreamUtils类属于com.badlogic.gdx.utils包,在下文中一共展示了StreamUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadGameStateSync
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
/**
* Blocking version of {@link #loadGameState(String, ILoadGameStateResponseListener)}
*
* @param fileId
* @return game state data
* @throws IOException
*/
public byte[] loadGameStateSync(String fileId) throws IOException {
InputStream stream = null;
byte[] data = null;
try {
File remoteFile = findFileByNameSync(fileId);
if (remoteFile != null) {
stream = GApiGateway.drive.files().get(remoteFile.getId()).executeMediaAsInputStream();
data = StreamUtils.copyStreamToByteArray(stream);
}
} finally {
StreamUtils.closeQuietly(stream);
}
return data;
}
示例2: download
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
public static byte[] download(String url) throws IOException {
InputStream in = null;
try {
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setDoInput(true);
conn.setDoOutput(false);
conn.setUseCaches(true);
conn.connect();
in = conn.getInputStream();
return StreamUtils.copyStreamToByteArray(in);
} catch (IOException ex) {
throw ex;
} finally {
StreamUtils.closeQuietly(in);
}
}
示例3: hashFile
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
public static String hashFile(FileHandle fileHandle) throws Exception {
InputStream inputStream = fileHandle.read();
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] bytesBuffer = new byte[1024];
int bytesRead;
int n =inputStream.read(bytesBuffer);
while ((bytesRead = n) != -1) {
digest.update(bytesBuffer, 0, bytesRead);
n=inputStream.read(bytesBuffer);
}
byte[] hashedBytes = digest.digest();
return convertByteArrayToHexString(hashedBytes);
} catch (IOException ex) {
throw new CubesException("Could not generate hash from file " + fileHandle.path(), ex);
} finally {
StreamUtils.closeQuietly(inputStream);
}
}
示例4: hashFile
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
public static String hashFile(FileHandle fileHandle) throws Exception {
InputStream inputStream = fileHandle.read();
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] bytesBuffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(bytesBuffer)) != -1) {
digest.update(bytesBuffer, 0, bytesRead);
}
byte[] hashedBytes = digest.digest();
return convertByteArrayToHexString(hashedBytes);
} catch (IOException ex) {
throw new CubesException("Could not generate hash from file " + fileHandle.path(), ex);
} finally {
StreamUtils.closeQuietly(inputStream);
}
}
示例5: getResult
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
public byte[] getResult () {
InputStream input = getInputStream();
// If the response does not contain any content, input will be null.
if (input == null) {
return StreamUtils.EMPTY_BYTES;
}
try {
return StreamUtils.copyStreamToByteArray(input, connection.getContentLength());
} catch (IOException e) {
return StreamUtils.EMPTY_BYTES;
} finally {
StreamUtils.closeQuietly(input);
}
}
示例6: getResultAsString
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
public String getResultAsString () {
InputStream input = getInputStream();
// If the response does not contain any content, input will be null.
if (input == null) {
return "";
}
try {
return StreamUtils.copyStreamToString(input, connection.getContentLength());
} catch (IOException e) {
return "";
} finally {
StreamUtils.closeQuietly(input);
}
}
示例7: Sound
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
public Sound (OpenALAudio audio, FileHandle file) {
super(audio);
if (audio.noDevice) return;
OggInputStream input = null;
try {
input = new OggInputStream(file.read());
ByteArrayOutputStream output = new ByteArrayOutputStream(4096);
byte[] buffer = new byte[2048];
while (!input.atEnd()) {
int length = input.read(buffer);
if (length == -1) break;
output.write(buffer, 0, length);
}
setup(output.toByteArray(), input.getChannels(), input.getSampleRate());
} finally {
StreamUtils.closeQuietly(input);
}
}
示例8: loadAsync
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void loadAsync (AssetManager manager, String fileName, FileHandle file, BehaviorTreeParameter parameter) {
this.behaviorTree = null;
Object blackboard = null;
BehaviorTreeParser parser = null;
if (parameter != null) {
blackboard = parameter.blackboard;
parser = parameter.parser;
}
if (parser == null) parser = new BehaviorTreeParser();
Reader reader = null;
try {
reader = file.reader();
this.behaviorTree = parser.parse(reader, blackboard);
} finally {
StreamUtils.closeQuietly(reader);
}
}
示例9: parse
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
/** Parses the given reader.
* @param reader the reader
* @throws SerializationException if the reader cannot be successfully parsed. */
public void parse (Reader reader) {
try {
char[] data = new char[1024];
int offset = 0;
while (true) {
int length = reader.read(data, offset, data.length - offset);
if (length == -1) break;
if (length == 0) {
char[] newData = new char[data.length * 2];
System.arraycopy(data, 0, newData, 0, data.length);
data = newData;
} else
offset += length;
}
parse(data, 0, offset);
} catch (IOException ex) {
throw new SerializationException(ex);
} finally {
StreamUtils.closeQuietly(reader);
}
}
示例10: ExperienceTable
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
public ExperienceTable(FileHandle file) {
requiredExpGain = new ObjectMap<Integer, Integer>();
requiredExpTotal = new ObjectMap<Integer, Integer>();
CSVReader reader = new CSVReader(file.reader());
try {
String[] line = reader.readNext();
int total = 0;
for (int i = 0; i < line.length; ++i) {
int currGain = Integer.parseInt(line[i]);
requiredExpGain.put(i+2, currGain);
total += currGain;
requiredExpTotal.put(i+2, total);
}
} catch (IOException e) {
throw new GdxRuntimeException(e);
} finally {
StreamUtils.closeQuietly(reader);
}
}
示例11: downloadFile
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
/** Synchronously downloads file by URL*/
public static void downloadFile(FileHandle output, String urlString) throws IOException {
// ReadableByteChannel rbc = null;
// FileOutputStream fos = null;
// try {
// URL url = new URL(urlString);
// rbc = Channels.newChannel(url.openStream());
// fos = new FileOutputStream(output.file());
// fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
// } finally {
// StreamUtils.closeQuietly(rbc);
// StreamUtils.closeQuietly(fos);
// }
InputStream in = null;
FileOutputStream out = null;
try {
URL url = new URL(urlString);
in = url.openStream();
out = new FileOutputStream(output.file());
StreamUtils.copyStream(in, out);
} finally {
StreamUtils.closeQuietly(in);
StreamUtils.closeQuietly(out);
}
}
示例12: unpackZip
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
public static void unpackZip(FileHandle input, FileHandle output) throws IOException {
ZipFile zipFile = new ZipFile(input.file());
File outputDir = output.file();
try {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
File entryDestination = new File(outputDir, entry.getName());
if (entry.isDirectory()) {
entryDestination.mkdirs();
} else {
entryDestination.getParentFile().mkdirs();
InputStream in = zipFile.getInputStream(entry);
OutputStream out = new FileOutputStream(entryDestination);
StreamUtils.copyStream(in, out);
StreamUtils.closeQuietly(in);
out.close();
}
}
} finally {
StreamUtils.closeQuietly(zipFile);
}
}
示例13: ETC1Data
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
public ETC1Data (FileHandle pkmFile) {
byte[] buffer = new byte[1024 * 10];
DataInputStream in = null;
try {
in = new DataInputStream(new BufferedInputStream(new GZIPInputStream(pkmFile.read())));
int fileSize = in.readInt();
compressedData = BufferUtils.newUnsafeByteBuffer(fileSize);
int readBytes = 0;
while ((readBytes = in.read(buffer)) != -1) {
compressedData.put(buffer, 0, readBytes);
}
compressedData.position(0);
compressedData.limit(compressedData.capacity());
} catch (Exception e) {
throw new GdxRuntimeException("Couldn't load pkm file '" + pkmFile + "'", e);
} finally {
StreamUtils.closeQuietly(in);
}
width = getWidthPKM(compressedData, 0);
height = getHeightPKM(compressedData, 0);
dataOffset = PKM_HEADER_SIZE;
compressedData.position(dataOffset);
checkNPOT();
}
示例14: loadEmitters
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
public void loadEmitters (FileHandle effectFile) {
InputStream input = effectFile.read();
emitters.clear();
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(input), 512);
while (true) {
ParticleEmitter emitter = new ParticleEmitter(reader);
emitters.add(emitter);
if (reader.readLine() == null) break;
if (reader.readLine() == null) break;
}
} catch (IOException ex) {
throw new GdxRuntimeException("Error loading effect: " + effectFile, ex);
} finally {
StreamUtils.closeQuietly(reader);
}
}
示例15: load
import com.badlogic.gdx.utils.StreamUtils; //导入依赖的package包/类
/** Loads a PolygonRegion from a PSH (Polygon SHape) file. The PSH file format defines the polygon vertices before
* triangulation:
* <p>
* s 200.0, 100.0, ...
* <p>
* Lines not prefixed with "s" are ignored. PSH files can be created with external tools, eg: <br>
* https://code.google.com/p/libgdx-polygoneditor/ <br>
* http://www.codeandweb.com/physicseditor/
* @param file file handle to the shape definition file */
public PolygonRegion load (TextureRegion textureRegion, FileHandle file) {
BufferedReader reader = file.reader(256);
try {
while (true) {
String line = reader.readLine();
if (line == null) break;
if (line.startsWith("s")) {
// Read shape.
String[] polygonStrings = line.substring(1).trim().split(",");
float[] vertices = new float[polygonStrings.length];
for (int i = 0, n = vertices.length; i < n; i++)
vertices[i] = Float.parseFloat(polygonStrings[i]);
// It would probably be better if PSH stored the vertices and triangles, then we don't have to triangulate here.
return new PolygonRegion(textureRegion, vertices, triangulator.computeTriangles(vertices).toArray());
}
}
} catch (IOException ex) {
throw new GdxRuntimeException("Error reading polygon shape file: " + file, ex);
} finally {
StreamUtils.closeQuietly(reader);
}
throw new GdxRuntimeException("Polygon shape not found: " + file);
}