use of java.io.OutputStream in project bazel by bazelbuild.
the class SkylarkRepositoryIntegrationTest method testCycleErrorInWorkspaceFileWithExternalRepo.
@Test
public void testCycleErrorInWorkspaceFileWithExternalRepo() throws Exception {
try (OutputStream output = scratch.resolve("WORKSPACE").getOutputStream(true)) {
output.write(("\nload('//foo:bar.bzl', 'foobar')" + "\ngit_repository(name = 'git_repo')").getBytes(StandardCharsets.UTF_8));
}
scratch.file("BUILD", "");
scratch.file("foo/BUILD", "");
scratch.file("foo/bar.bzl", "load('@git_repo//xyz:foo.bzl', 'rule_from_git')", "rule_from_git(name = 'foobar')");
invalidatePackages();
try {
getTarget("@//:git_repo");
fail();
} catch (AssertionError expected) {
assertThat(expected.getMessage()).contains("Failed to load Skylark extension " + "'@git_repo//xyz:foo.bzl'.\n" + "It usually happens when the repository is not defined prior to being used.\n" + "Maybe repository 'git_repo' was defined later in your WORKSPACE file?");
}
}
use of java.io.OutputStream in project cas by apereo.
the class OneTimeTokenQRGeneratorController method generateQRCode.
private static void generateQRCode(final OutputStream stream, final String key) {
try {
final Map<EncodeHintType, Object> hintMap = new EnumMap<>(EncodeHintType.class);
hintMap.put(EncodeHintType.CHARACTER_SET, StandardCharsets.UTF_8.name());
hintMap.put(EncodeHintType.MARGIN, 2);
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
final QRCodeWriter qrCodeWriter = new QRCodeWriter();
final BitMatrix byteMatrix = qrCodeWriter.encode(key, BarcodeFormat.QR_CODE, 250, 250, hintMap);
final int width = byteMatrix.getWidth();
final BufferedImage image = new BufferedImage(width, width, BufferedImage.TYPE_INT_RGB);
image.createGraphics();
final Graphics2D graphics = (Graphics2D) image.getGraphics();
try {
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, width, width);
graphics.setColor(Color.BLACK);
IntStream.range(0, width).forEach(i -> {
IntStream.range(0, width).filter(j -> byteMatrix.get(i, j)).forEach(j -> graphics.fillRect(i, j, 1, 1));
});
} finally {
graphics.dispose();
}
ImageIO.write(image, "png", stream);
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
use of java.io.OutputStream in project glide by bumptech.
the class StreamEncoder method encode.
@Override
public boolean encode(InputStream data, File file, Options options) {
byte[] buffer = byteArrayPool.get(ArrayPool.STANDARD_BUFFER_SIZE_BYTES, byte[].class);
boolean success = false;
OutputStream os = null;
try {
os = new FileOutputStream(file);
int read;
while ((read = data.read(buffer)) != -1) {
os.write(buffer, 0, read);
}
os.close();
success = true;
} catch (IOException e) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Failed to encode data onto the OutputStream", e);
}
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
// Do nothing.
}
}
byteArrayPool.put(buffer, byte[].class);
}
return success;
}
use of java.io.OutputStream in project CoreNLP by stanfordnlp.
the class SimpleSentiment method main.
public static void main(String[] args) throws IOException {
RedwoodConfiguration.standard().apply();
startTrack("main");
// Read the data
Stream<SentimentDatum> data = Stream.concat(Stream.concat(Stream.concat(imdb("/users/gabor/tmp/aclImdb/train/pos", SentimentClass.POSITIVE), imdb("/users/gabor/tmp/aclImdb/train/neg", SentimentClass.NEGATIVE)), Stream.concat(imdb("/users/gabor/tmp/aclImdb/test/pos", SentimentClass.POSITIVE), imdb("/users/gabor/tmp/aclImdb/test/neg", SentimentClass.NEGATIVE))), Stream.concat(Stream.concat(stanford("/users/gabor/tmp/train.tsv"), stanford("/users/gabor/tmp/test.tsv")), Stream.concat(twitter("/users/gabor/tmp/twitter.csv"), unlabelled("/users/gabor/tmp/wikipedia"))));
// Train the model
OutputStream stream = IOUtils.getFileOutputStream("/users/gabor/tmp/model.ser.gz");
SimpleSentiment classifier = SimpleSentiment.train(data, Optional.of(stream));
stream.close();
log.info(classifier.classify("I think life is great"));
endTrack("main");
// 85.8
}
use of java.io.OutputStream in project enroscar by stanfy.
the class ImageRequest method writeBitmapToDisk.
void writeBitmapToDisk(final Bitmap bitmap) throws IOException {
EnhancedResponseCache cache = (EnhancedResponseCache) manager.getImagesResponseCache();
OutputStream output = new FileOutputStream(cache.getLocalPath(url));
output = manager.getBuffersPool().bufferize(output, IMAGES_BUFFER_SIZE);
try {
final int quality = 100;
bitmap.compress(Bitmap.CompressFormat.PNG, quality, output);
} finally {
IoUtils.closeQuietly(output);
}
}
Aggregations