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


Java StreamUtils.closeQuietly方法代码示例

本文整理汇总了Java中com.badlogic.gdx.utils.StreamUtils.closeQuietly方法的典型用法代码示例。如果您正苦于以下问题:Java StreamUtils.closeQuietly方法的具体用法?Java StreamUtils.closeQuietly怎么用?Java StreamUtils.closeQuietly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.badlogic.gdx.utils.StreamUtils的用法示例。


在下文中一共展示了StreamUtils.closeQuietly方法的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;
}
 
开发者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: 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);
  }
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:22,代码来源:AndroidModLoader.java

示例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);
  }
}
 
开发者ID:RedTroop,项目名称:Cubes,代码行数:21,代码来源:AndroidModLoader.java

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

示例6: 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);
    }
}
 
开发者ID:crashinvaders,项目名称:gdx-texture-packer-gui,代码行数:24,代码来源:FileUtils.java

示例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);
	}
}
 
开发者ID:Xemiru,项目名称:Undertailor,代码行数:19,代码来源:Ogg.java

示例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);
	}
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:23,代码来源:BehaviorTreeLoader.java

示例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);
	}
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:25,代码来源:BehaviorTreeReader.java

示例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);
	}
}
 
开发者ID:mganzarcik,项目名称:fabulae,代码行数:20,代码来源:ExperienceTable.java

示例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);
        }
    }
 
开发者ID:crashinvaders,项目名称:gdx-texture-packer-gui,代码行数:26,代码来源:FileUtils.java

示例12: Sound

import com.badlogic.gdx.utils.StreamUtils; //导入方法依赖的package包/类
public Sound(OpenALAudio audio, FileHandle file) {
    super(audio);
    if (audio.noDevice) {
        return;
    }

    WavInputStream input = null;
    try {
        input = new WavInputStream(file);
        setup(StreamUtils.copyStreamToByteArray(input, input.dataRemaining), input.channels, input.sampleRate);
    } catch (IOException ex) {
        throw new GdxRuntimeException("Error reading WAV file: " + file, ex);
    } finally {
        StreamUtils.closeQuietly(input);
    }
}
 
开发者ID:kovertopz,项目名称:libGDX-LWJGL-Audio,代码行数:17,代码来源:Wav.java

示例13: createActor

import com.badlogic.gdx.utils.StreamUtils; //导入方法依赖的package包/类
@Override
public Actor createActor (Skin skin) {
	// Create the semaphore
	NonBlockingSemaphoreRepository.clear();
	NonBlockingSemaphoreRepository.addSemaphore("dogSemaphore", 1);

	Reader reader = null;
	try {
		// Parse Buddy's tree
		reader = Gdx.files.internal("data/dogSemaphore.tree").reader();
		BehaviorTreeParser<Dog> parser = new BehaviorTreeParser<Dog>(BehaviorTreeParser.DEBUG_HIGH);
		BehaviorTree<Dog> buddyTree = parser.parse(reader, new Dog("Buddy"));

		// Clone Buddy's tree for Snoopy
		BehaviorTree<Dog> snoopyTree = (BehaviorTree<Dog>)buddyTree.cloneTask();
		snoopyTree.setObject(new Dog("Snoopy"));

		// Create split pane
		BehaviorTreeViewer<?> buddyTreeViewer = createTreeViewer(buddyTree.getObject().name, buddyTree, false, skin);
		BehaviorTreeViewer<?> snoopyTreeViewer = createTreeViewer(snoopyTree.getObject().name, snoopyTree, false, skin);
		return new SplitPane(new ScrollPane(buddyTreeViewer, skin), new ScrollPane(snoopyTreeViewer, skin), true, skin,
			"default-horizontal");
	} finally {
		StreamUtils.closeQuietly(reader);
	}
}
 
开发者ID:libgdx,项目名称:gdx-ai,代码行数:27,代码来源:SemaphoreGuardTest.java

示例14: readString

import com.badlogic.gdx.utils.StreamUtils; //导入方法依赖的package包/类
/** Reads the entire file into a string using the specified charset.
 * @param charset If null the default charset is used.
 * @throws GdxRuntimeException if the file handle represents a directory, doesn't exist, or could not be read. */
public String readString (String charset) {
	StringBuilder output = new StringBuilder(estimateLength());
	InputStreamReader reader = null;
	try {
		if (charset == null)
			reader = new InputStreamReader(read());
		else
			reader = new InputStreamReader(read(), charset);
		char[] buffer = new char[256];
		while (true) {
			int length = reader.read(buffer);
			if (length == -1) break;
			output.append(buffer, 0, length);
		}
	} catch (IOException ex) {
		throw new GdxRuntimeException("Error reading layout file: " + this, ex);
	} finally {
		StreamUtils.closeQuietly(reader);
	}
	return output.toString();
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:25,代码来源:FileHandle.java

示例15: 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);
	}
}
 
开发者ID:fauu,项目名称:HelixEngine,代码行数:19,代码来源:ParticleEffect.java


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