当前位置: 首页>>代码示例>>Java>>正文


Java StreamUtils.copyStreamToByteArray方法代码示例

本文整理汇总了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;
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:25,代码来源:GpgsClient.java

示例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);
    }
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:17,代码来源:DownloadUtil.java

示例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);
	}
}
 
开发者ID:Radomiej,项目名称:JavityEngine,代码行数:17,代码来源:JavityNetJavaImpl.java

示例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);
	}
}
 
开发者ID:Quexten,项目名称:RavTech,代码行数:12,代码来源:ArchiveFileHandle.java

示例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);
}
 
开发者ID:intrigus,项目名称:gdx-freetype-gwt,代码行数:36,代码来源:FreeTypeFontGenerator.java

示例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);
	}
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:12,代码来源:NetJavaImpl.java

示例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);
	}
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:13,代码来源:FileHandle.java


注:本文中的com.badlogic.gdx.utils.StreamUtils.copyStreamToByteArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。