コード例 #1
0
    public byte[] decode(String code) {
      ByteArrayOutputStream baos = new ByteArrayOutputStream((code.length() * 3 / 4));

      StringReader sr;

      if (code.endsWith(Character.toString(padding))) {
        sr = new StringReader(code.substring(0, code.indexOf(padding)));
      } else {
        sr = new StringReader(code);
      }

      char[] c = new char[4];
      int[] b = new int[4];
      int len;
      try {
        int count = 0;
        while ((len = sr.read(c, 0, 4)) == 4) {
          b[0] = decode[c[0]];
          b[1] = decode[c[1]];
          b[2] = decode[c[2]];
          b[3] = decode[c[3]];

          baos.write(((b[0] & 0x3f) << 2) | ((b[1] & 0x30) >> 4));
          baos.write(((b[1] & 0x0f) << 4) | ((b[2] & 0x3c) >> 2));
          baos.write(((b[2] & 0x03) << 6) | (b[3] & 0x3f));

          count++;
          if (count == 19) {
            sr.mark(1);
            count = 0;

            if (sr.read() != 10) {
              sr.reset();
            }
          }
        }

        b[0] = decode[c[0]];
        b[1] = decode[c[1]];
        b[2] = decode[c[2]];
        b[3] = decode[c[3]];

        if (len == 2) {
          baos.write(((b[0] & 0x3f) << 2) | ((b[1] & 0x30) >> 4));
        } else if (len == 3) {
          baos.write(((b[0] & 0x3f) << 2) | ((b[1] & 0x30) >> 4));
          baos.write(((b[1] & 0x0f) << 4) | ((b[2] & 0x3c) >> 2));
        }

        return baos.toByteArray();
      } catch (java.io.IOException e) {
        return null;
      } catch (RuntimeException e) {
        return null;
      }
    }
コード例 #2
0
 /**
  * Compile a string into a function or SimpleVariable.
  *
  * <p>Called by {@link #compileString(String)} when that has detected "${".
  *
  * <p>Calls {@link CompoundVariable#getNamedFunction(String)} if it detects: '(' - start of
  * parameter list '}' - end of function call
  *
  * @param reader points to input after the "${"
  * @return the function or variable object (or a String)
  */
 Object makeFunction(StringReader reader) throws InvalidVariableException {
   char[] current = new char[1];
   char previous = ' '; // TODO - why use space?
   StringBuilder buffer = new StringBuilder();
   Object function;
   try {
     while (reader.read(current) == 1) {
       if (current[0] == '\\') {
         if (reader.read(current) == 0) {
           break;
         }
         previous = ' ';
         buffer.append(current[0]);
         continue;
       } else if (current[0] == '(' && previous != ' ') {
         String funcName = buffer.toString();
         function = CompoundVariable.getNamedFunction(funcName);
         if (function instanceof Function) {
           ((Function) function).setParameters(parseParams(reader));
           if (reader.read(current) == 0 || current[0] != '}') {
             reader.reset(); // set to start of string
             char[] cb = new char[100];
             reader.read(cb); // return deliberately ignored
             throw new InvalidVariableException(
                 "Expected } after " + funcName + " function call in " + new String(cb));
           }
           if (function instanceof TestListener) {
             StandardJMeterEngine.register((TestListener) function);
           }
           return function;
         } else { // Function does not exist, so treat as per missing variable
           buffer.append(current[0]);
         }
         continue;
       } else if (current[0] == '}') { // variable, or function with no parameter list
         function = CompoundVariable.getNamedFunction(buffer.toString());
         if (function instanceof Function) { // ensure that setParameters() is called.
           ((Function) function).setParameters(new LinkedList<CompoundVariable>());
         }
         buffer.setLength(0);
         return function;
       } else {
         buffer.append(current[0]);
         previous = current[0];
       }
     }
   } catch (IOException e) {
     log.error("Error parsing function: " + buffer.toString(), e);
     return null;
   }
   log.warn("Probably an invalid function string: " + buffer.toString());
   return buffer.toString();
 }
 private void execute() {
   try {
     Method mth = PreparedStatement.class.getDeclaredMethod(this.methodName, this.argClasses);
     mth.invoke(wrapped, args);
     if (args[1] instanceof StringReader) {
       StringReader sr = (StringReader) args[1];
       sr.reset();
     }
     if (args[1] instanceof InputStream
         && ("setAsciiStream".equals(methodName) || "setUnicodeStream".equals(methodName))) {
       ((InputStream) args[1]).reset();
     }
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
コード例 #4
0
 /**
  * Repositions this stream to the position at the time the <code>mark</code> method was last
  * called on this input stream.
  */
 public void reset() throws IOException {
   in.reset();
 }