test_class.file: cosmic-common/src/test/java/com/cloud/utils/encoding/UrlEncoderTest.java
test_class.identifier: UrlEncoderTest
test_case.body: @Test
      public void encode() {
          Assert.assertEquals("%2Ftmp%2F", new URLEncoder().encode("/tmp/"));
          Assert.assertEquals("%20", new URLEncoder().encode(" "));
          Assert.assertEquals("%5F", new URLEncoder().encode("_"));
          Assert.assertEquals("%25", new URLEncoder().encode("%"));
      }
test_case.class_method_signature: UrlEncoderTest.encode()
test_case.full_signature: @Test public void encode()
test_case.identifier: encode
test_case.invocations: assertEquals encode assertEquals encode assertEquals encode assertEquals encode
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void encode()
focal_class.declarator: hexadecimal = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}
focal_class.modifier: protected static final
focal_class.original_string: protected static final char[] hexadecimal = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
focal_class.type: char[]
focal_class.var_name: hexadecimal
focal_class.declarator: asciiEncoder = Charset.forName("US-ASCII").newEncoder()
focal_class.modifier: static
focal_class.original_string: static CharsetEncoder asciiEncoder = Charset.forName("US-ASCII").newEncoder();
focal_class.type: CharsetEncoder
focal_class.var_name: asciiEncoder
focal_class.declarator: safeCharacters = new BitSet(256)
focal_class.modifier: protected
focal_class.original_string: protected BitSet safeCharacters = new BitSet(256);
focal_class.type: BitSet
focal_class.var_name: safeCharacters
focal_class.file: cosmic-common/src/main/java/com/cloud/utils/encoding/URLEncoder.java
focal_class.identifier: URLEncoder
focal_class.class_method_signature: URLEncoder.URLEncoder()
focal_class.full_signature: public  URLEncoder()
focal_class.identifier: URLEncoder
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  URLEncoder()
focal_class.class_method_signature: URLEncoder.addSafeCharacter(final char c)
focal_class.full_signature: private void addSafeCharacter(final char c)
focal_class.identifier: addSafeCharacter
focal_class.modifiers: private
focal_class.parameters: (final char c)
focal_class.return: void
focal_class.signature: void addSafeCharacter(final char c)
focal_class.class_method_signature: URLEncoder.encode(final String path)
focal_class.full_signature: public String encode(final String path)
focal_class.identifier: encode
focal_class.modifiers: public
focal_class.parameters: (final String path)
focal_class.return: String
focal_class.signature: String encode(final String path)
focal_class.class_method_signature: URLEncoder.isPureAscii(final Character v)
focal_class.full_signature: public static boolean isPureAscii(final Character v)
focal_class.identifier: isPureAscii
focal_class.modifiers: public static
focal_class.parameters: (final Character v)
focal_class.return: boolean
focal_class.signature: boolean isPureAscii(final Character v)
focal_method.body: public String encode(final String path) {
          final int maxBytesPerChar = 10;
          final StringBuffer rewrittenPath = new StringBuffer(path.length());
          final ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar);
          OutputStreamWriter writer = null;
          try {
              writer = new OutputStreamWriter(buf, "UTF8");
          } catch (final Exception e) {
              e.printStackTrace();
              writer = new OutputStreamWriter(buf);
          }
  
          for (int i = 0; i < path.length(); i++) {
              final int c = path.charAt(i);
              // NOTICE - !isPureAscii(path.charAt(i)) check was added by
              // CloudStack
              if (safeCharacters.get(c) || !isPureAscii(path.charAt(i))) {
                  rewrittenPath.append((char) c);
              } else {
                  // convert to external encoding before hex conversion
                  try {
                      writer.write((char) c);
                      writer.flush();
                  } catch (final IOException e) {
                      buf.reset();
                      continue;
                  }
                  final byte[] ba = buf.toByteArray();
                  for (int j = 0; j < ba.length; j++) {
                      // Converting each byte in the buffer
                      final byte toEncode = ba[j];
                      rewrittenPath.append('%');
                      final int low = toEncode & 0x0f;
                      final int high = (toEncode & 0xf0) >> 4;
                      rewrittenPath.append(hexadecimal[high]);
                      rewrittenPath.append(hexadecimal[low]);
                  }
                  buf.reset();
              }
          }
          return rewrittenPath.toString();
      }
focal_method.class_method_signature: URLEncoder.encode(final String path)
focal_method.full_signature: public String encode(final String path)
focal_method.identifier: encode
focal_method.invocations: length printStackTrace length charAt get isPureAscii charAt append write flush reset toByteArray append append append reset toString
focal_method.modifiers: public
focal_method.parameters: (final String path)
focal_method.return: String
focal_method.signature: String encode(final String path)