use of java.io.OutputStreamWriter in project libgdx by libgdx.
the class TexturePacker method writePackFile.
private void writePackFile(File outputDir, String scaledPackFileName, Array<Page> pages) throws IOException {
File packFile = new File(outputDir, scaledPackFileName + settings.atlasExtension);
File packDir = packFile.getParentFile();
packDir.mkdirs();
if (packFile.exists()) {
// Make sure there aren't duplicate names.
TextureAtlasData textureAtlasData = new TextureAtlasData(new FileHandle(packFile), new FileHandle(packFile), false);
for (Page page : pages) {
for (Rect rect : page.outputRects) {
String rectName = Rect.getAtlasName(rect.name, settings.flattenPaths);
for (Region region : textureAtlasData.getRegions()) {
if (region.name.equals(rectName)) {
throw new GdxRuntimeException("A region with the name \"" + rectName + "\" has already been packed: " + rect.name);
}
}
}
}
}
Writer writer = new OutputStreamWriter(new FileOutputStream(packFile, true), "UTF-8");
for (Page page : pages) {
writer.write("\n" + page.imageName + "\n");
writer.write("size: " + page.imageWidth + "," + page.imageHeight + "\n");
writer.write("format: " + settings.format + "\n");
writer.write("filter: " + settings.filterMin + "," + settings.filterMag + "\n");
writer.write("repeat: " + getRepeatValue() + "\n");
page.outputRects.sort();
for (Rect rect : page.outputRects) {
writeRect(writer, page, rect, rect.name);
Array<Alias> aliases = new Array(rect.aliases.toArray());
aliases.sort();
for (Alias alias : aliases) {
Rect aliasRect = new Rect();
aliasRect.set(rect);
alias.apply(aliasRect);
writeRect(writer, page, aliasRect, alias.name);
}
}
}
writer.close();
}
use of java.io.OutputStreamWriter in project libgdx by libgdx.
the class FilesTest method create.
@Override
public void create() {
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
batch = new SpriteBatch();
if (Gdx.files.isExternalStorageAvailable()) {
message += "External storage available\n";
message += "External storage path: " + Gdx.files.getExternalStoragePath() + "\n";
try {
InputStream in = Gdx.files.internal("data/cube.obj").read();
StreamUtils.closeQuietly(in);
message += "Open internal success\n";
} catch (Throwable e) {
message += "Couldn't open internal data/cube.obj\n" + e.getMessage() + "\n";
}
BufferedWriter out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(Gdx.files.external("test.txt").write(false)));
out.write("test");
message += "Write external success\n";
} catch (GdxRuntimeException ex) {
message += "Couldn't open externalstorage/test.txt\n";
} catch (IOException e) {
message += "Couldn't write externalstorage/test.txt\n";
} finally {
StreamUtils.closeQuietly(out);
}
try {
InputStream in = Gdx.files.external("test.txt").read();
StreamUtils.closeQuietly(in);
message += "Open external success\n";
} catch (Throwable e) {
message += "Couldn't open internal externalstorage/test.txt\n" + e.getMessage() + "\n";
}
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(Gdx.files.external("test.txt").read()));
if (!in.readLine().equals("test"))
message += "Read result wrong\n";
else
message += "Read external success\n";
} catch (GdxRuntimeException ex) {
message += "Couldn't open externalstorage/test.txt\n";
} catch (IOException e) {
message += "Couldn't read externalstorage/test.txt\n";
} finally {
StreamUtils.closeQuietly(in);
}
if (!Gdx.files.external("test.txt").delete())
message += "Couldn't delete externalstorage/test.txt";
} else {
message += "External storage not available";
}
if (Gdx.files.isLocalStorageAvailable()) {
message += "Local storage available\n";
message += "Local storage path: " + Gdx.files.getLocalStoragePath() + "\n";
BufferedWriter out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(Gdx.files.local("test.txt").write(false)));
out.write("test");
message += "Write local success\n";
} catch (GdxRuntimeException ex) {
message += "Couldn't open localstorage/test.txt\n";
} catch (IOException e) {
message += "Couldn't write localstorage/test.txt\n";
} finally {
StreamUtils.closeQuietly(out);
}
try {
InputStream in = Gdx.files.local("test.txt").read();
StreamUtils.closeQuietly(in);
message += "Open local success\n";
} catch (Throwable e) {
message += "Couldn't open localstorage/test.txt\n" + e.getMessage() + "\n";
}
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(Gdx.files.local("test.txt").read()));
if (!in.readLine().equals("test"))
message += "Read result wrong\n";
else
message += "Read local success\n";
} catch (GdxRuntimeException ex) {
message += "Couldn't open localstorage/test.txt\n";
} catch (IOException e) {
message += "Couldn't read localstorage/test.txt\n";
} finally {
StreamUtils.closeQuietly(in);
}
try {
byte[] testBytes = Gdx.files.local("test.txt").readBytes();
if (Arrays.equals("test".getBytes(), testBytes))
message += "Read into byte array success\n";
else
fail();
} catch (Throwable e) {
message += "Couldn't read localstorage/test.txt\n" + e.getMessage() + "\n";
}
if (!Gdx.files.local("test.txt").delete())
message += "Couldn't delete localstorage/test.txt";
}
try {
testClasspath();
testInternal();
testExternal();
testAbsolute();
testLocal();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
use of java.io.OutputStreamWriter in project bazel by bazelbuild.
the class SourceManifestAction method writeFile.
/**
* Sort the entries in both the normal and root manifests and write the output
* file.
*
* @param out is the message stream to write errors to.
* @param output The actual mapping of the output manifest.
* @throws IOException
*/
private void writeFile(OutputStream out, Map<PathFragment, Artifact> output) throws IOException {
Writer manifestFile = new BufferedWriter(new OutputStreamWriter(out, ISO_8859_1));
Comparator<Map.Entry<PathFragment, Artifact>> fragmentComparator = new Comparator<Map.Entry<PathFragment, Artifact>>() {
@Override
public int compare(Map.Entry<PathFragment, Artifact> path1, Map.Entry<PathFragment, Artifact> path2) {
return path1.getKey().compareTo(path2.getKey());
}
};
List<Map.Entry<PathFragment, Artifact>> sortedManifest = new ArrayList<>(output.entrySet());
Collections.sort(sortedManifest, fragmentComparator);
for (Map.Entry<PathFragment, Artifact> line : sortedManifest) {
manifestWriter.writeEntry(manifestFile, line.getKey(), line.getValue());
}
manifestFile.flush();
}
use of java.io.OutputStreamWriter in project blade by biezhi.
the class StreamKit method writeText.
/** 将字符串写入到指定输出流中。 */
public static void writeText(CharSequence chars, OutputStream out, String charset, boolean closeOut) throws IOException {
Writer writer = charset == null ? new OutputStreamWriter(out) : new OutputStreamWriter(out, charset);
writeText(chars, writer, closeOut);
}
use of java.io.OutputStreamWriter in project HanLP by hankcs.
the class TestPhrase method testExtract.
public void testExtract() throws Exception {
List<File> fileList = FolderWalker.open(FOLDER);
Map<String, String> phraseMap = new TreeMap<String, String>();
int i = 0;
for (File file : fileList) {
System.out.print(++i + " / " + fileList.size() + " " + file.getName() + " ");
String path = file.getAbsolutePath();
List<String> phraseList = MutualInformationEntropyPhraseExtractor.extract(IOUtil.readTxt(path), 3);
System.out.print(phraseList);
for (String phrase : phraseList) {
phraseMap.put(phrase, file.getAbsolutePath());
}
System.out.println();
}
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("data/phrase.txt")));
for (Map.Entry<String, String> entry : phraseMap.entrySet()) {
bw.write(entry.getKey() + "\t" + entry.getValue());
bw.newLine();
}
bw.close();
}
Aggregations