本文整理汇总了Java中com.badlogic.gdx.utils.StreamUtils.copyStreamToByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java StreamUtils.copyStreamToByteArray方法的具体用法?Java StreamUtils.copyStreamToByteArray怎么用?Java StreamUtils.copyStreamToByteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.utils.StreamUtils
的用法示例。
在下文中一共展示了StreamUtils.copyStreamToByteArray方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
}
示例4: readBytes
import com.badlogic.gdx.utils.StreamUtils; //导入方法依赖的package包/类
@Override
public byte[] readBytes () {
InputStream input = read();
try {
return StreamUtils.copyStreamToByteArray(input, 512);
} catch (IOException ex) {
throw new GdxRuntimeException("Error reading file: " + this, ex);
} finally {
StreamUtils.closeQuietly(input);
}
}
示例5: FreeTypeFontGenerator
import com.badlogic.gdx.utils.StreamUtils; //导入方法依赖的package包/类
/** Creates a new generator from the given font file. Uses {@link FileHandle#length()} to determine the file size. If the file
* length could not be determined (it was 0), an extra copy of the font bytes is performed. Throws a
* {@link GdxRuntimeException} if loading did not succeed. */
public FreeTypeFontGenerator (FileHandle fontFile) {
name = fontFile.pathWithoutExtension();
int fileSize = (int)fontFile.length();
library = FreeType.initFreeType();
if (library == null) throw new GdxRuntimeException("Couldn't initialize FreeType");
ByteBuffer buffer;
InputStream input = fontFile.read();
try {
if (fileSize == 0) {
// Copy to a byte[] to get the file size, then copy to the buffer.
byte[] data = StreamUtils.copyStreamToByteArray(input, fileSize > 0 ? (int)(fileSize * 1.5f) : 1024 * 16);
buffer = BufferUtils.newByteBuffer(data.length);
BufferUtils.copy(data, 0, buffer, data.length);
} else {
// Trust the specified file size.
buffer = BufferUtils.newByteBuffer(fileSize);
StreamUtils.copyStream(input, buffer);
}
} catch (IOException ex) {
throw new GdxRuntimeException(ex);
} finally {
StreamUtils.closeQuietly(input);
}
face = library.newMemoryFace(buffer, 0);
if (face == null) throw new GdxRuntimeException("Couldn't create face for font: " + fontFile);
if (checkForBitmapFont()) return;
setPixelSizes(0, 15);
}
示例6: getResult
import com.badlogic.gdx.utils.StreamUtils; //导入方法依赖的package包/类
@Override
public byte[] getResult () {
InputStream input = getInputStream();
try {
return StreamUtils.copyStreamToByteArray(input, connection.getContentLength());
} catch (IOException e) {
return StreamUtils.EMPTY_BYTES;
} finally {
StreamUtils.closeQuietly(input);
}
}
示例7: readBytes
import com.badlogic.gdx.utils.StreamUtils; //导入方法依赖的package包/类
/** Reads the entire file into a byte array.
* @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */
public byte[] readBytes () {
InputStream input = read();
try {
return StreamUtils.copyStreamToByteArray(input, estimateLength());
} catch (IOException ex) {
throw new GdxRuntimeException("Error reading file: " + this, ex);
} finally {
StreamUtils.closeQuietly(input);
}
}