private void loadAnswers(File folder) { // if(!folder.exists() && !folder.isDirectory()) // return; File f = folder; // for(File f: folder.listFiles()){ if (f.getName().contains("answer")) { // if(f.getName().equals(this.answerPath)){ // continue; // }else{ this.answerPath = f.getName(); // } try { ((DefaultTableModel) topKTable.getModel()).setRowCount(0); answers.clear(); InputStreamReader reader = new InputStreamReader(new FileInputStream(f), "ASCII"); AnswerCodingArray.Builder builder = AnswerCodingArray.newBuilder(); TextFormat.merge(reader, builder); AnswerCodingArray answer_array = builder.build(); for (int i = 0; i < answer_array.getAnswersCount(); i++) { answers.add(answer_array.getAnswers(i)); } } catch (Exception e) { System.out.println(e.toString()); } } // } Collections.sort(answers, new AnswerComparator()); ((DefaultTableModel) topKTable.getModel()).setRowCount(answers.size()); for (int i = 0; i < answers.size(); i++) { this.topKTable.setValueAt(i + 1, i, 0); this.topKTable.setValueAt(answers.get(i).getScore(), i, 1); } }
@Test public void basic() throws Exception { TestingDataProcessor processor = TestingDataProcessor.loadData( h2Info.connection.get(), Files.toString(new File(TESTDATA_PATH + "guide_plan.data"), Charsets.UTF_8)); for (Pair<String, String> entry : processor.getCases()) { GuidePlanRequest.Builder reqBuilder = GuidePlanRequest.newBuilder(); TextFormat.merge(entry.getValue0(), reqBuilder); GuidePlanResponse.Builder respBuilder = GuidePlanResponse.newBuilder(); TextFormat.merge(entry.getValue1(), respBuilder); GuidePlanRequestHandler handler = injector.getInstance(GuidePlanRequestHandler.class); Assert.assertEquals(respBuilder.build(), handler.process(reqBuilder.build())); } }
@Override public CompilerPass getProcessor(final Compiler compiler) { ConformanceConfig.Builder builder = ConformanceConfig.newBuilder(); try { TextFormat.merge(configuration, builder); } catch (Exception e) { Throwables.propagate(e); } return new CheckConformance(compiler, ImmutableList.of(builder.build())); }
/** * Creates an intrument functions compiler pass. * * @param compiler The JSCompiler * @param functionNames Assigned function identifiers. * @param templateFilename Template filename; for use during error reporting only. * @param appNameStr String to pass to appNameSetter. * @param readable Instrumentation template protobuf text. */ InstrumentFunctions( AbstractCompiler compiler, FunctionNames functionNames, String templateFilename, String appNameStr, Readable readable) { this.compiler = compiler; this.functionNames = functionNames; this.templateFilename = templateFilename; this.appNameStr = appNameStr; Instrumentation.Builder builder = Instrumentation.newBuilder(); try { TextFormat.merge(readable, builder); } catch (IOException e) { compiler.report( JSError.make( RhinoErrorReporter.PARSE_ERROR, "Error reading instrumentation template protobuf at " + templateFilename)); this.initCodeSource = ""; this.definedFunctionName = ""; this.reportFunctionName = ""; this.reportFunctionExitName = ""; this.appNameSetter = ""; this.declarationsToRemove = Lists.newArrayList(); return; } Instrumentation template = builder.build(); StringBuilder initCodeSourceBuilder = new StringBuilder(); for (String line : template.getInitList()) { initCodeSourceBuilder.append(line).append("\n"); } this.initCodeSource = initCodeSourceBuilder.toString(); this.definedFunctionName = template.getReportDefined(); this.reportFunctionName = template.getReportCall(); this.reportFunctionExitName = template.getReportExit(); this.appNameSetter = template.getAppNameSetter(); this.declarationsToRemove = ImmutableList.copyOf(template.getDeclarationToRemoveList()); }
@Override public String toString() { return TextFormat.shortDebugString(getProto()); }
/** @param requirement */ private static void reportInvalidRequirement( AbstractCompiler compiler, Requirement requirement, String reason) { compiler.report( JSError.make(INVALID_REQUIREMENT_SPEC, reason, TextFormat.printToString(requirement))); }
@Override public Integer apply(Pair<RequestHeader, Message> headerAndParam) { RequestHeader header = headerAndParam.getFirst(); String methodName = header.getMethodName(); Integer priorityByAnnotation = annotatedQos.get(methodName); if (priorityByAnnotation != null) { return priorityByAnnotation; } Message param = headerAndParam.getSecond(); if (param == null) { return HConstants.NORMAL_QOS; } if (methodName.equalsIgnoreCase("multi") && param instanceof MultiRequest) { // The multi call has its priority set in the header. All calls should work this way but // only this one has been converted so far. No priority == NORMAL_QOS. return header.hasPriority() ? header.getPriority() : HConstants.NORMAL_QOS; } String cls = param.getClass().getName(); Class<? extends Message> rpcArgClass = argumentToClassMap.get(cls); RegionSpecifier regionSpecifier = null; // check whether the request has reference to meta region or now. try { // Check if the param has a region specifier; the pb methods are hasRegion and getRegion if // hasRegion returns true. Not all listed methods have region specifier each time. For // example, the ScanRequest has it on setup but thereafter relies on the scannerid rather than // send the region over every time. Method hasRegion = methodMap.get("hasRegion").get(rpcArgClass); if (hasRegion != null && (Boolean) hasRegion.invoke(param, (Object[]) null)) { Method getRegion = methodMap.get("getRegion").get(rpcArgClass); regionSpecifier = (RegionSpecifier) getRegion.invoke(param, (Object[]) null); HRegion region = hRegionServer.getRegion(regionSpecifier); if (region.getRegionInfo().isMetaTable()) { if (LOG.isTraceEnabled()) { LOG.trace("High priority because region=" + region.getRegionNameAsString()); } return HConstants.HIGH_QOS; } } } catch (Exception ex) { // Not good throwing an exception out of here, a runtime anyways. Let the query go into the // server and have it throw the exception if still an issue. Just mark it normal priority. if (LOG.isTraceEnabled()) LOG.trace("Marking normal priority after getting exception=" + ex); return HConstants.NORMAL_QOS; } if (methodName.equals("scan")) { // scanner methods... ScanRequest request = (ScanRequest) param; if (!request.hasScannerId()) { return HConstants.NORMAL_QOS; } RegionScanner scanner = hRegionServer.getScanner(request.getScannerId()); if (scanner != null && scanner.getRegionInfo().isMetaRegion()) { if (LOG.isTraceEnabled()) { // Scanner requests are small in size so TextFormat version should not overwhelm log. LOG.trace("High priority scanner request " + TextFormat.shortDebugString(request)); } return HConstants.HIGH_QOS; } } return HConstants.NORMAL_QOS; }
@Override public final String toString() { return TextFormat.printToString(this); }
/** * Returns the given wallet formatted as text. The text format is that used by protocol buffers * and although it can also be parsed using {@link TextFormat#merge(CharSequence, * com.google.protobuf.Message.Builder)}, it is designed more for debugging than storage. It is * not well specified and wallets are largely binary data structures anyway, consisting as they do * of keys (large random numbers) and {@link Transaction}s which also mostly contain keys and * hashes. */ public String walletToText(Wallet wallet) { Protos.Wallet walletProto = walletToProto(wallet); return TextFormat.printToString(walletProto); }
public static String toString(MajorType type) { return type != null ? "MajorType[" + TextFormat.shortDebugString(type) + "]" : "null"; }