本文整理了Java中org.openimaj.io.IOUtils.writeASCII()
方法的一些代码示例,展示了IOUtils.writeASCII()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.writeASCII()
方法的具体详情如下:
包路径:org.openimaj.io.IOUtils
类名称:IOUtils
方法名:writeASCII
[英]Writeable object is written to the a file in ASCII format. File stream is opened and stream version is called
[中]可写对象以ASCII格式写入文件。打开文件流并调用流版本
代码示例来源:origin: openimaj/openimaj
@Override
public String toString() {
StringWriter writer = new StringWriter();
try {
IOUtils.writeASCII(writer, this);
} catch (IOException e) {
return "ERRORSTRING";
}
return writer.toString();
}
代码示例来源:origin: org.openimaj.hadoop.tools/HadoopTwitterTokenTool
@Override
public String toString() {
StringWriter writer = new StringWriter();
try {
IOUtils.writeASCII(writer, this);
} catch (IOException e) {
return "ERRORSTRING";
}
return writer.toString();
}
代码示例来源:origin: openimaj/openimaj
@Override
protected void reduce(LongWritable time, java.lang.Iterable<Text> words, org.apache.hadoop.mapreduce.Reducer<LongWritable,Text,NullWritable,Text>.Context context) throws java.io.IOException ,InterruptedException {
HashSet<String> unseenwords = new HashSet<String>();
StringWriter writer = new StringWriter();
for (Text text : words) {
unseenwords.add(text.toString());
}
long intersection = 0;
for (String string : unseenwords) {
if(this.seenwords.contains(string)) intersection += 1;
this.seenwords.add(string);
}
JacardIndex index = new JacardIndex(time.get(),intersection,this.seenwords.size());
IOUtils.writeASCII(writer, index);
context.write(NullWritable.get(), new Text(writer.toString()));
};
}
代码示例来源:origin: openimaj/openimaj
@Override
public void newImageDownloaded(WriteableImageOutput written) {
try {
StringWriter writer = new StringWriter();
IOUtils.writeASCII(writer, written);
publisher.send("IMAGE".getBytes("UTF-8"), ZMQ.SNDMORE);
boolean sent = publisher.send(writer.toString().getBytes("UTF-8"), 0);
if(!sent){
throw new IOException("Send failed");
}
} catch (IOException e) {
logger.error("Unable to send written image: " + written.url);
logger.error(e.getMessage());
}
}
代码示例来源:origin: openimaj/openimaj
/**
* Write an object to a file fully. The object will be saved with class
* information so that it can be automatically re-instantiated using
* {@link #read(File)} without needing to know the actual type.
*
* @param <T>
* instance type expected
* @param f
* the file
* @param object
* the object to write
* @throws IOException
* problem reading file
*/
public static <T extends WriteableASCII> void writeASCIIFull(File f, T object) throws IOException {
IOUtils.writeASCII(f, new ObjectWrapper(object));
}
代码示例来源:origin: org.openimaj.hadoop.tools/HadoopTwitterTokenTool
@Override
protected void reduce(LongWritable time, java.lang.Iterable<Text> words, org.apache.hadoop.mapreduce.Reducer<LongWritable,Text,NullWritable,Text>.Context context) throws java.io.IOException ,InterruptedException {
HashSet<String> unseenwords = new HashSet<String>();
StringWriter writer = new StringWriter();
for (Text text : words) {
unseenwords.add(text.toString());
}
long intersection = 0;
for (String string : unseenwords) {
if(this.seenwords.contains(string)) intersection += 1;
this.seenwords.add(string);
}
JacardIndex index = new JacardIndex(time.get(),intersection,this.seenwords.size());
IOUtils.writeASCII(writer, index);
context.write(NullWritable.get(), new Text(writer.toString()));
};
}
代码示例来源:origin: openimaj/openimaj
@Override
protected void reduce(Text word, java.lang.Iterable<BytesWritable> dfidfs, Reducer<Text,BytesWritable,NullWritable,Text>.Context context) throws java.io.IOException ,InterruptedException {
WordDFIDFTimeSeries dts = new WordDFIDFTimeSeries();
for (BytesWritable bytesWritable : dfidfs) {
WordDFIDF wd = IOUtils.deserialize(bytesWritable.getBytes(), WordDFIDF.class);
dts.add(wd.timeperiod, wd);
}
StringWriter writer = new StringWriter();
writer.write(word + " ");
IOUtils.writeASCII(writer, dts);
context.write(NullWritable.get(), new Text(writer .toString()));
};
}
代码示例来源:origin: org.openimaj.hadoop.tools/HadoopTwitterTokenTool
@Override
protected void reduce(Text word, java.lang.Iterable<BytesWritable> dfidfs, Reducer<Text,BytesWritable,NullWritable,Text>.Context context) throws java.io.IOException ,InterruptedException {
WordDFIDFTimeSeries dts = new WordDFIDFTimeSeries();
for (BytesWritable bytesWritable : dfidfs) {
WordDFIDF wd = IOUtils.deserialize(bytesWritable.getBytes(), WordDFIDF.class);
dts.add(wd.timeperiod, wd);
}
StringWriter writer = new StringWriter();
writer.write(word + " ");
IOUtils.writeASCII(writer, dts);
context.write(NullWritable.get(), new Text(writer .toString()));
};
}
代码示例来源:origin: openimaj/openimaj
@Override
public void failedURL(URL url, String reason) {
try {
StringWriter writer = new StringWriter();
if(url==null)return;
IOUtils.writeASCII(writer, new WriteableFailedURL(url, reason));
publisher.send("FAIL".getBytes("UTF-8"), ZMQ.SNDMORE);
boolean sent = publisher.send(writer.toString().getBytes("UTF-8"), 0);
if(!sent){
throw new IOException("Send failed");
}
} catch (IOException e) {
logger.error("Unable to send failure!");
}
}
代码示例来源:origin: openimaj/openimaj
void execute() throws IOException {
FImage mask = FloodFill.floodFill(input, px, py, thresh);
if (maskoutput != null)
ImageUtilities.write(mask, maskoutput.getName().substring(maskoutput.getName().lastIndexOf(".") + 1), maskoutput);
if (feature != null) {
FeatureVector fv = featureOp.execute(input, mask);
if (binary)
IOUtils.writeBinary(output, fv);
else
IOUtils.writeASCII(output, fv);
}
}
代码示例来源:origin: org.openimaj.tools/GlobalFeaturesTool
void execute() throws IOException {
FeatureVector fv = featureOp.extract(input);
if (binary)
IOUtils.writeBinary(output, fv);
else
IOUtils.writeASCII(output, fv);
}
代码示例来源:origin: openimaj/openimaj
@Override
protected void reduce(LongWritable time, Iterable<BytesWritable> inersectionUnionBs, Reducer<LongWritable,BytesWritable,NullWritable,Text>.Context context) throws IOException ,InterruptedException {
long intersection = 0;
long union = 0;
for (BytesWritable intersectionUnionb : inersectionUnionBs) {
ReadWritableBooleanBoolean intersectionUnion = IOUtils.deserialize(intersectionUnionb.getBytes(), ReadWritableBooleanBoolean.class);
intersection += intersectionUnion.firstObject() ? 1 : 0;
union += intersectionUnion.secondObject() ? 1 : 0;
}
JacardIndex jind = new JacardIndex(time.get(),intersection,union);
StringWriter writer = new StringWriter();
IOUtils.writeASCII(writer, jind);
context.write(NullWritable.get(), new Text(writer.toString()));
};
}
代码示例来源:origin: org.openimaj.hadoop.tools/HadoopTwitterTokenTool
@Override
protected void reduce(LongWritable time, Iterable<BytesWritable> inersectionUnionBs, Reducer<LongWritable,BytesWritable,NullWritable,Text>.Context context) throws IOException ,InterruptedException {
long intersection = 0;
long union = 0;
for (BytesWritable intersectionUnionb : inersectionUnionBs) {
ReadWritableBooleanBoolean intersectionUnion = IOUtils.deserialize(intersectionUnionb.getBytes(), ReadWritableBooleanBoolean.class);
intersection += intersectionUnion.firstObject() ? 1 : 0;
union += intersectionUnion.secondObject() ? 1 : 0;
}
JacardIndex jind = new JacardIndex(time.get(),intersection,union);
StringWriter writer = new StringWriter();
IOUtils.writeASCII(writer, jind);
context.write(NullWritable.get(), new Text(writer.toString()));
};
}
代码示例来源:origin: openimaj/openimaj
void execute() throws IOException {
FeatureVector fv = featureOp.extract(input);
if (binary)
IOUtils.writeBinary(output, fv);
else
IOUtils.writeASCII(output, fv);
}
代码示例来源:origin: org.openimaj.tools/GlobalFeaturesTool
void execute() throws IOException {
FImage mask = FloodFill.floodFill(input, px, py, thresh);
if (maskoutput != null)
ImageUtilities.write(mask, maskoutput.getName().substring(maskoutput.getName().lastIndexOf(".") + 1), maskoutput);
if (feature != null) {
FeatureVector fv = featureOp.execute(input, mask);
if (binary)
IOUtils.writeBinary(output, fv);
else
IOUtils.writeASCII(output, fv);
}
}
代码示例来源:origin: openimaj/openimaj
@Override
protected void
map(Text key, BytesWritable value, Mapper<Text, BytesWritable, Text, BytesWritable>.Context context)
throws InterruptedException
{
try {
final MBFImage img = ImageUtilities.readMBF(new ByteArrayInputStream(value.getBytes()));
final FeatureVector fv = options.featureOp.extract(img);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (options.binary)
IOUtils.writeBinary(baos, fv);
else
IOUtils.writeASCII(baos, fv);
context.write(key, new BytesWritable(baos.toByteArray()));
} catch (final Exception e) {
logger.warn("Problem processing image " + key + " (" + e + ")");
}
}
}
代码示例来源:origin: org.openimaj.hadoop.tools/HadoopTwitterTokenTool
@Override
public void finished(Job job) {
final Path out = new Path(actualOutputLocation, PAIR_STATS_FILE);
FileSystem fs;
try {
fs = HadoopToolsUtil.getFileSystem(out);
final FSDataOutputStream os = fs.create(out);
IOUtils.writeASCII(os, new WritablePairEnum(job.getCounters(), PairEnum.values()));
} catch (final IOException e) {
}
}
代码示例来源:origin: openimaj/openimaj
@Override
public void finished(Job job) {
final Path out = new Path(actualOutputLocation, PAIR_STATS_FILE);
FileSystem fs;
try {
fs = HadoopToolsUtil.getFileSystem(out);
final FSDataOutputStream os = fs.create(out);
IOUtils.writeASCII(os, new WritablePairEnum(job.getCounters(), PairEnum.values()));
} catch (final IOException e) {
}
}
代码示例来源:origin: openimaj/openimaj
/**
* Main method
*
* @param args
* ignored
* @throws IOException
* if the image can't be read
*/
public static void main(String[] args) throws IOException {
// read an image
final FImage image = ImageUtilities.readF(OpenIMAJ.getLogoAsStream());
// create the extractor - this can be reused (and is thread-safe)
final DoGSIFTEngine engine = new DoGSIFTEngine();
// find interest points in the image and extract SIFT descriptors
final LocalFeatureList<Keypoint> keypoints = engine.findFeatures(image);
// print the interest points to stdout
IOUtils.writeASCII(System.out, keypoints);
}
}
代码示例来源:origin: openimaj/openimaj
@Override
public void perform(File input) {
try {
final byte[] img = options.getInputImage(input);
final Timer timing = Timer.timer();
final LocalFeatureList<? extends LocalFeature<?, ?>> kpl = options.getMode().extract(img);
timing.stop();
if (options.printTiming()) {
System.out.println("Took: " + timing.duration());
}
if (options.isAsciiMode()) {
IOUtils.writeASCII(options.getOutput(input), kpl);
} else {
IOUtils.writeBinary(options.getOutput(input), kpl);
}
} catch (final IOException e) {
System.err.println(e);
}
}
}, pool);
内容来源于网络,如有侵权,请联系作者删除!