List of usage examples for org.apache.hadoop.io BytesWritable getBytes
@Override public byte[] getBytes()
From source file:com.marcolotz.lung.debug.InputTester.java
License:Creative Commons License
/*** * Method used for local testing the record reader and the Input format. It * generates an input split from the local file system file. * //from ww w .j a v a 2 s . c om * @param filePath */ public void localTest(String filePath) { DICOM image; Configuration testConf = new Configuration(false); /* Reads the local file system */ testConf.set("fs.default.name", "file:///"); File testFile = new File(filePath); Path path = new Path(testFile.getAbsoluteFile().toURI()); FileSplit split = new FileSplit(path, 0, testFile.length(), null); InputFormat<NullWritable, BytesWritable> inputFormat = ReflectionUtils .newInstance(WholeFileInputFormat.class, testConf); TaskAttemptContext context = new TaskAttemptContextImpl(testConf, new TaskAttemptID()); try { RecordReader<NullWritable, BytesWritable> reader = inputFormat.createRecordReader(split, context); while (reader.nextKeyValue()) { /* get the bytes array */ BytesWritable inputBytesWritable = (BytesWritable) reader.getCurrentValue(); byte[] inputContent = inputBytesWritable.getBytes(); /* Check for Correct value */ // generateLocalOutput("path/to/output"); InputStream is = new ByteArrayInputStream(inputContent); image = new DICOM(is); image.run("Dicom Test"); /* Prints the bytes as an ImagePlus image */ ImageViewer debug = new ImageViewer(); debug.setImage(image); } } catch (Exception e) { } }
From source file:com.marcolotz.lung.mapper.LungMapper.java
License:Creative Commons License
/** * Converts from bytesWritable to DICOM image. * //w w w. j a v a 2s . c o m * @param dicomImage * @return DICOM image */ private DICOM convertToDICOM(BytesWritable dicomImage) { byte[] inputContent = dicomImage.getBytes(); InputStream inputStream = new ByteArrayInputStream(inputContent); DICOM convertedImage = new DICOM(inputStream); // Gives a generic name to the image file convertedImage.run("Dicom Image"); return convertedImage; }
From source file:com.marklogic.mapreduce.examples.BinaryReader.java
License:Apache License
@Override public void write(DocumentURI uri, BytesWritable content) throws IOException, InterruptedException { String pathStr = dir.getName() + uri.getUri(); Path path = new Path(pathStr); FileSystem fs = path.getFileSystem(conf); FSDataOutputStream out = fs.create(path, false); System.out.println("writing to: " + path); out.write(content.getBytes(), 0, content.getLength()); out.flush();/* w w w . ja v a2s . c o m*/ out.close(); }
From source file:com.metamx.druid.indexer.SortableBytes.java
License:Open Source License
public static SortableBytes fromBytesWritable(BytesWritable bytes) { return fromBytes(bytes.getBytes(), 0, bytes.getLength()); }
From source file:com.mvdb.etl.dao.impl.JdbcGenericDAO.java
License:Apache License
@Override public boolean scan2(String objectName, File snapshotDirectory) { String hadoopLocalFS = "file:///"; Configuration conf = new Configuration(); conf.set("fs.defaultFS", hadoopLocalFS); String dataFileName = "data-" + objectName + ".dat"; File dataFile = new File(snapshotDirectory, dataFileName); Path path = new Path(dataFile.getAbsolutePath()); FileSystem fs;/*w w w . j a v a2 s . c o m*/ try { fs = FileSystem.get(conf); SequenceFile.Reader reader = new SequenceFile.Reader(fs, path, conf); Text key = new Text(); BytesWritable value = new BytesWritable(); while (reader.next(key, value)) { byte[] bytes = value.getBytes(); ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); GenericDataRecord dr = (GenericDataRecord) ois.readObject(); System.out.println(dr.toString()); } IOUtils.closeStream(reader); } catch (IOException e) { logger.error("scan2():", e); return false; } catch (ClassNotFoundException e) { logger.error("scan2():", e); return false; } return true; }
From source file:com.mvdb.platform.action.ScanDBTable.java
License:Apache License
public static boolean scan(String dataFileName) { File dataFile = new File(dataFileName); String hadoopLocalFS = "file:///"; Configuration conf = new Configuration(); conf.set("fs.defaultFS", hadoopLocalFS); // String dataFileName = "data-" + objectName + ".dat"; // File dataFile = new File(snapshotDirectory, dataFileName); Path path = new Path(dataFile.getAbsolutePath()); FileSystem fs;//from w ww .j a v a2s . co m try { fs = FileSystem.get(conf); SequenceFile.Reader reader = new SequenceFile.Reader(fs, path, conf); Text key = new Text(); BytesWritable value = new BytesWritable(); while (reader.next(key, value)) { byte[] bytes = value.getBytes(); ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); Object object = ois.readObject(); if (object instanceof GenericDataRecord) { GenericDataRecord dr = (GenericDataRecord) object; System.out.println(dr.toString()); } if (object instanceof MultiVersionRecord) { MultiVersionRecord mvr = (MultiVersionRecord) object; System.out.println(mvr.toString()); } } IOUtils.closeStream(reader); } catch (IOException e) { logger.error("scan2():", e); return false; } catch (ClassNotFoundException e) { logger.error("scan2():", e); return false; } return true; }
From source file:com.mvdb.scratch.HadoopClient.java
License:Apache License
public static void readSequenceFile(String sequenceFileName, String hadoopFS) throws IOException { Path path = new Path(sequenceFileName); conf.set("fs.defaultFS", hadoopFS); FileSystem fs = FileSystem.get(conf); SequenceFile.Reader reader = new SequenceFile.Reader(fs, path, conf); IntWritable key = new IntWritable(); // this could be the wrong type BytesWritable value = new BytesWritable(); // also could be wrong while (reader.next(key, value)) { System.out.println(key + ":" + new String(value.getBytes())); }//from w w w .j a va 2s. c o m IOUtils.closeStream(reader); }
From source file:com.philiphubbard.digraph.MREdge.java
License:Open Source License
public static boolean getIsMREdge(BytesWritable writable) { byte[] bytes = writable.getBytes(); return (bytes[0] == WRITABLE_TYPE_ID); }
From source file:com.philiphubbard.digraph.MREdge.java
License:Open Source License
public MREdge(BytesWritable writable) { byte[] bytes = writable.getBytes(); from = getInt(bytes, 1); to = getInt(bytes, 5); }
From source file:com.philiphubbard.digraph.MRVertex.java
License:Open Source License
public static boolean getIsMRVertex(BytesWritable writable) { byte[] array = writable.getBytes(); return (array[0] == WRITABLE_TYPE_ID); }