@GET
 @Produces(MIMETYPE_BINARY)
 public Response getBinary(final @Context UriInfo uriInfo) {
   if (LOG.isDebugEnabled()) {
     LOG.debug("GET " + uriInfo.getAbsolutePath() + " as " + MIMETYPE_BINARY);
   }
   servlet.getMetrics().incrementRequests(1);
   try {
     KeyValue value = generator.next();
     if (value == null) {
       LOG.info("generator exhausted");
       return Response.noContent().build();
     }
     ResponseBuilder response = Response.ok(value.getValue());
     response.cacheControl(cacheControl);
     response.header("X-Row", Base64.encodeBytes(value.getRow()));
     response.header(
         "X-Column",
         Base64.encodeBytes(KeyValue.makeColumn(value.getFamily(), value.getQualifier())));
     response.header("X-Timestamp", value.getTimestamp());
     return response.build();
   } catch (IllegalStateException e) {
     ScannerResource.delete(id);
     throw new WebApplicationException(Response.Status.GONE);
   }
 }
示例#2
0
 public WritableByteArrayComparableModel(WritableByteArrayComparable comparator) {
   String typeName = comparator.getClass().getSimpleName();
   ComparatorType type = ComparatorType.valueOf(typeName);
   this.type = typeName;
   switch (type) {
     case BinaryComparator:
     case BinaryPrefixComparator:
       this.value = Base64.encodeBytes(comparator.getValue());
       break;
     case BitComparator:
       this.value = Base64.encodeBytes(comparator.getValue());
       this.op = ((BitComparator) comparator).getOperator().toString();
       break;
     case NullComparator:
       break;
     case RegexStringComparator:
     case SubstringComparator:
       this.value = Bytes.toString(comparator.getValue());
       break;
     default:
       throw new RuntimeException("unhandled filter type: " + type);
   }
 }
示例#3
0
  public void handle(HttpExchange t) throws IOException {
    // System.out.println(t.getRequestURI().toString());
    /*
     * InputStream is = t.getRequestBody(); byte[] temp = new
     * byte[is.available()]; is.read(temp); String title=new String(temp);
     */
    String title_str = t.getRequestURI().toString();
    // System.out.println("title_str:" + title_str);
    /*
     * Pattern tit_pat=Pattern.compile("\\/cate_db\\/do\\?t\\=(.*?)\\=");
     * Matcher tit_mat=tit_pat.matcher(title_str); String tt="";
     * while(tit_mat.find()) { tt=tit_mat.group(1);
     * System.out.println("title:"+tt); }
     */
    title_str = title_str.replaceFirst("/cate_tb/do\\?t=", "");
    // System.out.println("title_str:" + title_str);
    String de_title = new String(Base64.decode(title_str));
    System.out.println("de_title:" + de_title);
    String res = "";
    try {
      res = my_ewa.predict_from_seg_line(de_title);
    } catch (Exception e) {
    }
    ;
    System.out.println("res is :" + res);
    // res=res.replace("\001", "$");
    String encode_res = Base64.encodeBytes(res.getBytes());
    encode_res = encode_res.replaceAll("\\s+", "");
    System.out.println("encode_res:" + encode_res);

    String response = encode_res;
    t.sendResponseHeaders(200, response.length());
    OutputStream os = t.getResponseBody();
    os.write(response.getBytes());
    os.close();
  }
示例#4
0
 public FilterModel(Filter filter) {
   String typeName = filter.getClass().getSimpleName();
   FilterType type = FilterType.valueOf(typeName);
   this.type = typeName;
   switch (type) {
     case ColumnCountGetFilter:
       this.limit = ((ColumnCountGetFilter) filter).getLimit();
       break;
     case ColumnPaginationFilter:
       this.limit = ((ColumnPaginationFilter) filter).getLimit();
       this.offset = ((ColumnPaginationFilter) filter).getOffset();
       break;
     case ColumnPrefixFilter:
       this.value = Base64.encodeBytes(((ColumnPrefixFilter) filter).getPrefix());
       break;
     case ColumnRangeFilter:
       this.minColumn = Base64.encodeBytes(((ColumnRangeFilter) filter).getMinColumn());
       this.minColumnInclusive = ((ColumnRangeFilter) filter).getMinColumnInclusive();
       this.maxColumn = Base64.encodeBytes(((ColumnRangeFilter) filter).getMaxColumn());
       this.maxColumnInclusive = ((ColumnRangeFilter) filter).getMaxColumnInclusive();
       break;
     case DependentColumnFilter:
       {
         DependentColumnFilter dcf = (DependentColumnFilter) filter;
         this.family = Base64.encodeBytes(dcf.getFamily());
         byte[] qualifier = dcf.getQualifier();
         if (qualifier != null) {
           this.qualifier = Base64.encodeBytes(qualifier);
         }
         this.op = dcf.getOperator().toString();
         this.comparator = new WritableByteArrayComparableModel(dcf.getComparator());
         this.dropDependentColumn = dcf.dropDependentColumn();
       }
       break;
     case FilterList:
       this.op = ((FilterList) filter).getOperator().toString();
       this.filters = new ArrayList<FilterModel>();
       for (Filter child : ((FilterList) filter).getFilters()) {
         this.filters.add(new FilterModel(child));
       }
       break;
     case FirstKeyOnlyFilter:
     case KeyOnlyFilter:
       break;
     case InclusiveStopFilter:
       this.value = Base64.encodeBytes(((InclusiveStopFilter) filter).getStopRowKey());
       break;
     case MultipleColumnPrefixFilter:
       this.prefixes = new ArrayList<String>();
       for (byte[] prefix : ((MultipleColumnPrefixFilter) filter).getPrefix()) {
         this.prefixes.add(Base64.encodeBytes(prefix));
       }
       break;
     case PageFilter:
       this.value = Long.toString(((PageFilter) filter).getPageSize());
       break;
     case PrefixFilter:
       this.value = Base64.encodeBytes(((PrefixFilter) filter).getPrefix());
       break;
     case FamilyFilter:
     case QualifierFilter:
     case RowFilter:
     case ValueFilter:
       this.op = ((CompareFilter) filter).getOperator().toString();
       this.comparator =
           new WritableByteArrayComparableModel(((CompareFilter) filter).getComparator());
       break;
     case RandomRowFilter:
       this.chance = ((RandomRowFilter) filter).getChance();
       break;
     case SingleColumnValueExcludeFilter:
     case SingleColumnValueFilter:
       {
         SingleColumnValueFilter scvf = (SingleColumnValueFilter) filter;
         this.family = Base64.encodeBytes(scvf.getFamily());
         byte[] qualifier = scvf.getQualifier();
         if (qualifier != null) {
           this.qualifier = Base64.encodeBytes(qualifier);
         }
         this.op = scvf.getOperator().toString();
         this.comparator = new WritableByteArrayComparableModel(scvf.getComparator());
         if (scvf.getFilterIfMissing()) {
           this.ifMissing = true;
         }
         if (scvf.getLatestVersionOnly()) {
           this.latestVersion = true;
         }
       }
       break;
     case SkipFilter:
       this.filters = new ArrayList<FilterModel>();
       this.filters.add(new FilterModel(((SkipFilter) filter).getFilter()));
       break;
     case TimestampsFilter:
       this.timestamps = ((TimestampsFilter) filter).getTimestamps();
       break;
     case WhileMatchFilter:
       this.filters = new ArrayList<FilterModel>();
       this.filters.add(new FilterModel(((WhileMatchFilter) filter).getFilter()));
       break;
     default:
       throw new RuntimeException("unhandled filter type " + type);
   }
 }