public static LocalStructureJiang [][] loadLSMapFile(Configuration conf) { String name = conf.get(Util.MAPFILENAMEPROPERTY, Util.MAPFILEDEFAULTNAME); MapFile.Reader lsmapfile = Util.createMapFileReader(conf, name); LocalStructureJiang [][] result = null; WritableComparable<?> key = (WritableComparable<?>) ReflectionUtils.newInstance(lsmapfile.getKeyClass(), conf); LSJiangArray value = (LSJiangArray) ReflectionUtils.newInstance(lsmapfile.getValueClass(), conf); try { while(lsmapfile.next(key, value)) { result = (LocalStructureJiang [][]) ArrayUtils.add(result, Arrays.copyOf(value.get(), value.get().length, LocalStructureJiang[].class)); } } catch (Exception e) { System.err.println("LocalStructureJiang.loadLSMapFile: unable to read fingerprint " + key + " in MapFile " + name + ": " + e.getMessage()); e.printStackTrace(); } IOUtils.closeStream(lsmapfile); return result; }
public Map<String, Integer> loadInfoFile(Configuration conf) { String name = conf.get(Util.INFOFILENAMEPROPERTY, Util.INFOFILEDEFAULTNAME); MapFile.Reader infofile = Util.createMapFileReader(conf, name); Map<String, Integer> infomap = new HashMap<String,Integer>(); Text key = new Text(); IntWritable value = new IntWritable(); try { while(infofile.next(key, value)) { infomap.put(key.toString(), value.get()); } } catch (Exception e) { System.err.println("PartialScoreCylinder.loadInfoFile: unable to read fingerprint " + key + " in MapFile " + name + ": " + e.getMessage()); e.printStackTrace(); } IOUtils.closeStream(infofile); return infomap; }
public static Map<String, Minutia[]> loadInfoFile(Configuration conf) { Map<String, Minutia[]> infomap = new HashMap<String, Minutia[]>(); String name = conf.get(Util.INFOFILENAMEPROPERTY, Util.INFOFILEDEFAULTNAME); MapFile.Reader lsmapfile = Util.createMapFileReader(conf, name); WritableComparable<?> key = (WritableComparable<?>) ReflectionUtils.newInstance(lsmapfile.getKeyClass(), conf); MinutiaArray value = (MinutiaArray) ReflectionUtils.newInstance(lsmapfile.getValueClass(), conf); try { while(lsmapfile.next(key, value)) { Writable [] w = value.get(); infomap.put(key.toString(), Arrays.copyOf(w, w.length, Minutia[].class)); } } catch (Exception e) { System.err.println("PartialScoreLSSR.loadInfoFile: unable to read fingerprint " + key + " in MapFile " + name + ": " + e.getMessage()); e.printStackTrace(); } IOUtils.closeStream(lsmapfile); return infomap; }
public static LocalStructureCylinder [][] loadLSMapFile(Configuration conf) { String name = conf.get(Util.MAPFILENAMEPROPERTY, Util.MAPFILEDEFAULTNAME); MapFile.Reader lsmapfile = Util.createMapFileReader(conf, name); LocalStructureCylinder [][] result = null; WritableComparable<?> key = (WritableComparable<?>) ReflectionUtils.newInstance(lsmapfile.getKeyClass(), conf); LSCylinderArray value = (LSCylinderArray) ReflectionUtils.newInstance(lsmapfile.getValueClass(), conf); try { while(lsmapfile.next(key, value)) { result = (LocalStructureCylinder [][]) ArrayUtils.add(result, Arrays.copyOf(value.get(), value.get().length, LocalStructureCylinder[].class)); } } catch (Exception e) { System.err.println("LocalStructureCylinder.loadLSMapFile: unable to read fingerprint " + key + " in MapFile " + name + ": " + e.getMessage()); e.printStackTrace(); } IOUtils.closeStream(lsmapfile); return result; }
public static Map<String, Minutia[]> loadInfoFile(Configuration conf) { Map<String, Minutia[]> infomap = new HashMap<String, Minutia[]>(); String name = conf.get(Util.INFOFILENAMEPROPERTY, Util.INFOFILEDEFAULTNAME); MapFile.Reader lsmapfile = Util.createMapFileReader(conf, name); WritableComparable<?> key = (WritableComparable<?>) ReflectionUtils.newInstance(lsmapfile.getKeyClass(), conf); MinutiaArray value = (MinutiaArray) ReflectionUtils.newInstance(lsmapfile.getValueClass(), conf); try { while(lsmapfile.next(key, value)) { infomap.put(key.toString(), Arrays.copyOf(value.get(), value.get().length, Minutia[].class)); } } catch (Exception e) { System.err.println("PartialScoreLSSR.loadInfoFile: unable to read fingerprint " + key + " in MapFile " + name + ": " + e.getMessage()); e.printStackTrace(); } IOUtils.closeStream(lsmapfile); return infomap; }
private static void writeJobSplitMetaInfo(FileSystem fs, Path filename, FsPermission p, int splitMetaInfoVersion, JobSplit.SplitMetaInfo[] allSplitMetaInfo) throws IOException { // write the splits meta-info to a file for the job tracker FSDataOutputStream out = null; try { out = FileSystem.create(fs, filename, p); out.write(META_SPLIT_FILE_HEADER); WritableUtils.writeVInt(out, splitMetaInfoVersion); WritableUtils.writeVInt(out, allSplitMetaInfo.length); for(JobSplit.SplitMetaInfo splitMetaInfo: allSplitMetaInfo) { splitMetaInfo.write(out); } } finally { IOUtils.closeStream(out); } }
@SuppressWarnings({ "unchecked", "unused" }) private <T> T getSplitDetails(Path file, long offset) throws IOException { FileSystem fs = file.getFileSystem(getYarnConf()); FSDataInputStream inFile = null; T split = null; try { inFile = fs.open(file); inFile.seek(offset); String className = Text.readString(inFile); Class<T> cls; try { cls = (Class<T>) getYarnConf().getClassByName(className); } catch (ClassNotFoundException ce) { IOException wrap = new IOException(String.format("Split class %s not found", className)); wrap.initCause(ce); throw wrap; } SerializationFactory factory = new SerializationFactory(getYarnConf()); Deserializer<T> deserializer = (Deserializer<T>) factory.getDeserializer(cls); deserializer.open(inFile); split = deserializer.deserialize(null); } finally { IOUtils.closeStream(inFile); } return split; }
public static String readFile(File file) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); BufferedInputStream is = new BufferedInputStream(new FileInputStream(file)); try { IOUtils.copyBytes(is, os, 1024, true); } finally { is.close(); } return os.toString(); }
/** * Builds a SetTraceMask request to be sent to the server, consisting of * "stmk" followed by the 8-byte long representation of the trace mask. * * @param mask trace mask to set * @return built request * @throws IOException if there is an I/O error */ private String buildSetTraceMaskRequest(long mask) throws IOException { ByteArrayOutputStream baos = null; DataOutputStream dos = null; try { baos = new ByteArrayOutputStream(); dos = new DataOutputStream(baos); dos.writeBytes("stmk"); dos.writeLong(mask); } finally { IOUtils.closeStream(dos); IOUtils.closeStream(baos); } return new String(baos.toByteArray()); }
public void saveInfoFile(LocalStructure[][] inputls, Configuration conf) { String name = conf.get(Util.INFOFILENAMEPROPERTY, Util.INFOFILEDEFAULTNAME); MapFile.Writer lsmapfile = Util.createMapFileWriter(conf, name, Text.class, MinutiaArray.class); Arrays.sort(inputls, new Comparator<LocalStructure[]>() { public int compare(LocalStructure [] als1, LocalStructure [] als2) { return als1[0].getFpid().compareTo(als2[0].getFpid()); } }); Text fpid = new Text(); for(LocalStructure [] ails : inputls) { fpid.set(ails[0].getFpid()); Minutia [] ma = new Minutia[ails.length]; try { for(int i = 0; i < ails.length; i++) ma[i] = ((LocalStructureCylinder) ails[i]).getMinutia(); lsmapfile.append(fpid, new MinutiaArray(ma)); } catch (IOException e) { System.err.println("LocalStructure.saveInfoFile: unable to save fingerprint " + fpid.toString() + " in MapFile " + name + ": " + e.getMessage()); e.printStackTrace(); } } IOUtils.closeStream(lsmapfile); return; }
public static void saveLSMapFile(LocalStructure[][] inputls, Configuration conf) { String name = conf.get(Util.MAPFILENAMEPROPERTY, Util.MAPFILEDEFAULTNAME); MapFile.Writer lsmapfile = Util.createMapFileWriter(conf, name, Text.class, inputls[0][0].newArrayWritable().getClass()); Arrays.sort(inputls, new Comparator<LocalStructure[]>() { public int compare(LocalStructure [] als1, LocalStructure [] als2) { return als1[0].getFpid().compareTo(als2[0].getFpid()); } }); Text fpid = new Text(); ArrayWritable aw = null; for(LocalStructure [] ails : inputls) { fpid.set(ails[0].getFpid()); ails = Util.removeNonValidLS(ails); try { aw = ails[0].newArrayWritable(ails); lsmapfile.append(fpid, aw); } catch (IOException e) { System.err.println("LocalStructure.saveLSMapFile: unable to save fingerprint " + fpid.toString() + " in MapFile " + name + ": " + e.getMessage()); e.printStackTrace(); } } IOUtils.closeStream(lsmapfile); }
public static <T extends LocalStructure> LocalStructure [][] loadLSMapFile(Configuration conf) { String name = conf.get(Util.MAPFILENAMEPROPERTY, Util.MAPFILEDEFAULTNAME); int length = Integer.parseInt(conf.get(Util.MAPFILELENGTHPROPERTY)); MapFile.Reader lsmapfile = Util.createMapFileReader(conf, name); LocalStructure [][] result = new LocalStructure[length][]; int i = 0; WritableComparable<?> key = (WritableComparable<?>) ReflectionUtils.newInstance(lsmapfile.getKeyClass(), conf); ArrayWritable value = (ArrayWritable) ReflectionUtils.newInstance(lsmapfile.getValueClass(), conf); try { while(lsmapfile.next(key, value)) { Writable [] aw = value.get(); result[i] = (LocalStructure []) Arrays.copyOf(aw, aw.length, LocalStructure[].class); i++; } } catch (Exception e) { System.err.println("LocalStructure.loadLSMapFile: unable to read fingerprint " + key + " in MapFile " + name + ": " + e.getMessage()); e.printStackTrace(); } IOUtils.closeStream(lsmapfile); return result; }
public static void saveLSMapFile(LocalStructure[][] inputls, Configuration conf) { String name = conf.get(Util.MAPFILENAMEPROPERTY, Util.MAPFILEDEFAULTNAME); MapFile.Writer lsmapfile = Util.createMapFileWriter(conf, name, Text.class, inputls[0][0].newArrayWritable().getClass()); Arrays.sort(inputls, new Comparator<LocalStructure[]>() { public int compare(LocalStructure [] als1, LocalStructure [] als2) { return als1[0].getFpid().compareTo(als2[0].getFpid()); } }); Text fpid = new Text(); ArrayWritable aw = null; for(LocalStructure [] ails : inputls) { fpid.set(ails[0].getFpid()); try { aw = ails[0].newArrayWritable(ails); lsmapfile.append(fpid, aw); } catch (IOException e) { System.err.println("LocalStructureCylinder.saveLSMapFile: unable to save fingerprint " + fpid.toString() + " in MapFile " + name + ": " + e.getMessage()); e.printStackTrace(); } } IOUtils.closeStream(lsmapfile); }
public void saveInfoFile(LocalStructure[][] inputls, Configuration conf) { String name = conf.get(Util.INFOFILENAMEPROPERTY, Util.INFOFILEDEFAULTNAME); MapFile.Writer lsmapfile = Util.createMapFileWriter(conf, name, Text.class, MinutiaArray.class); Arrays.sort(inputls, new Comparator<LocalStructure[]>() { public int compare(LocalStructure [] als1, LocalStructure [] als2) { return als1[0].getFpid().compareTo(als2[0].getFpid()); } }); Text fpid = new Text(); for(LocalStructure [] ails : inputls) { fpid.set(ails[0].getFpid()); Minutia [] ma = new Minutia[ails.length]; try { for(int i = 0; i < ails.length; i++) ma[i] = ((LocalStructureCylinder) ails[i]).getMinutia(); lsmapfile.append(fpid, new MinutiaArray(ma)); } catch (IOException e) { System.err.println("LocalStructure.saveLSMapFile: unable to save fingerprint " + fpid.toString() + " in MapFile " + name + ": " + e.getMessage()); e.printStackTrace(); } } IOUtils.closeStream(lsmapfile); return; }