test_class.declarator: INPUT_FILE = new File("src/test/resource/resfilter/json/input.json")
test_class.modifier: private static final
test_class.original_string: private static final File INPUT_FILE = new File("src/test/resource/resfilter/json/input.json");
test_class.type: File
test_class.var_name: INPUT_FILE
test_class.declarator: OUTPUT_FILE = new File("src/test/resource/resfilter/json/output.json")
test_class.modifier: private static final
test_class.original_string: private static final File OUTPUT_FILE = new File("src/test/resource/resfilter/json/output.json");
test_class.type: File
test_class.var_name: OUTPUT_FILE
test_class.declarator: INPUT_FILE2 = new File("src/test/resource/resfilter/json/other-input.json")
test_class.modifier: private static final
test_class.original_string: private static final File INPUT_FILE2 = new File("src/test/resource/resfilter/json/other-input.json");
test_class.type: File
test_class.var_name: INPUT_FILE2
test_class.declarator: SPLITKEYS = new File("src/test/resource/resfilter/json/testSplitKeys.json")
test_class.modifier: private static final
test_class.original_string: private static final File SPLITKEYS = new File("src/test/resource/resfilter/json/testSplitKeys.json");
test_class.type: File
test_class.var_name: SPLITKEYS
test_class.declarator: EXPECTED_WRITE_FILE = new File("src/test/resource/resfilter/json/write-output.json")
test_class.modifier: private static final
test_class.original_string: private static final File EXPECTED_WRITE_FILE = new File("src/test/resource/resfilter/json/write-output.json");
test_class.type: File
test_class.var_name: EXPECTED_WRITE_FILE
test_class.declarator: EXPECTED_INPUT_RES_LIST
test_class.modifier: private static final
test_class.original_string: private static final Collection<ResourceString> EXPECTED_INPUT_RES_LIST;
test_class.type: Collection<ResourceString>
test_class.var_name: EXPECTED_INPUT_RES_LIST
test_class.declarator: WRITE_BUNDLE
test_class.modifier: private static
test_class.original_string: private static LanguageBundle WRITE_BUNDLE;
test_class.type: LanguageBundle
test_class.var_name: WRITE_BUNDLE
test_class.declarator: res = new JsonResource()
test_class.modifier: private static final
test_class.original_string: private static final JsonResource res = new JsonResource();
test_class.type: JsonResource
test_class.var_name: res
test_class.file: gp-res-filter/src/test/java/com/ibm/g11n/pipeline/resfilter/impl/JsonResourceTest.java
test_class.identifier: JsonResourceTest
test_case.body: @Test
      public void testWrite() throws IOException, ResourceFilterException {
          File tempFile = File.createTempFile(this.getClass().getSimpleName(), ".json");
          tempFile.deleteOnExit();
  
          try (OutputStream os = new FileOutputStream(tempFile)) {
              res.write(os, WRITE_BUNDLE, null);
              os.flush();
              ResourceTestUtil.compareFilesJson(EXPECTED_WRITE_FILE, tempFile);
          }
      }
test_case.class_method_signature: JsonResourceTest.testWrite()
test_case.full_signature: @Test public void testWrite()
test_case.identifier: testWrite
test_case.invocations: createTempFile getSimpleName getClass deleteOnExit write flush compareFilesJson
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testWrite()
focal_class.declarator: JSONPATH_ROOT = "$"
focal_class.modifier: private static final
focal_class.original_string: private static final String JSONPATH_ROOT = "$";
focal_class.type: String
focal_class.var_name: JSONPATH_ROOT
focal_class.declarator: USE_JSONPATH_PATTERN = Pattern.compile("^\\$[.\\[].*")
focal_class.modifier: private static final
focal_class.original_string: private static final Pattern USE_JSONPATH_PATTERN = Pattern.compile("^\\$[.\\[].*");
focal_class.type: Pattern
focal_class.var_name: USE_JSONPATH_PATTERN
focal_class.declarator: USE_BRACKET_PATTERN = Pattern.compile("[.'\\[\\]]")
focal_class.modifier: private static final
focal_class.original_string: private static final Pattern USE_BRACKET_PATTERN = Pattern.compile("[.'\\[\\]]");
focal_class.type: Pattern
focal_class.var_name: USE_BRACKET_PATTERN
focal_class.file: gp-res-filter/src/main/java/com/ibm/g11n/pipeline/resfilter/impl/JsonResource.java
focal_class.identifier: JsonResource
focal_class.class_method_signature: JsonResource.parse(InputStream inStream, FilterOptions options)
focal_class.full_signature: @Override public LanguageBundle parse(InputStream inStream, FilterOptions options)
focal_class.identifier: parse
focal_class.modifiers: @Override public
focal_class.parameters: (InputStream inStream, FilterOptions options)
focal_class.return: LanguageBundle
focal_class.signature: LanguageBundle parse(InputStream inStream, FilterOptions options)
focal_class.class_method_signature: JsonResource.addBundleStrings(JsonObject obj, String keyPrefix, LanguageBundleBuilder bb, int sequenceNum)
focal_class.full_signature: protected int addBundleStrings(JsonObject obj, String keyPrefix, LanguageBundleBuilder bb, int sequenceNum)
focal_class.identifier: addBundleStrings
focal_class.modifiers: protected
focal_class.parameters: (JsonObject obj, String keyPrefix, LanguageBundleBuilder bb, int sequenceNum)
focal_class.return: int
focal_class.signature: int addBundleStrings(JsonObject obj, String keyPrefix, LanguageBundleBuilder bb, int sequenceNum)
focal_class.class_method_signature: JsonResource.encodeResourceKey(String parent, String key, boolean isLeaf)
focal_class.full_signature: protected String encodeResourceKey(String parent, String key, boolean isLeaf)
focal_class.identifier: encodeResourceKey
focal_class.modifiers: protected
focal_class.parameters: (String parent, String key, boolean isLeaf)
focal_class.return: String
focal_class.signature: String encodeResourceKey(String parent, String key, boolean isLeaf)
focal_class.class_method_signature: JsonResource.write(OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_class.full_signature: @Override public void write(OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_class.identifier: write
focal_class.modifiers: @Override public
focal_class.parameters: (OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_class.return: void
focal_class.signature: void write(OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_class.class_method_signature: JsonResource.splitKeyPieces(String key)
focal_class.full_signature: static List<KeyPiece> splitKeyPieces(String key)
focal_class.identifier: splitKeyPieces
focal_class.modifiers: static
focal_class.parameters: (String key)
focal_class.return: List<KeyPiece>
focal_class.signature: List<KeyPiece> splitKeyPieces(String key)
focal_class.class_method_signature: JsonResource.addToken(List<KeyPiece> result, String s, boolean inSubscript)
focal_class.full_signature: static void addToken(List<KeyPiece> result, String s, boolean inSubscript)
focal_class.identifier: addToken
focal_class.modifiers: static
focal_class.parameters: (List<KeyPiece> result, String s, boolean inSubscript)
focal_class.return: void
focal_class.signature: void addToken(List<KeyPiece> result, String s, boolean inSubscript)
focal_class.superclass: extends ResourceFilter
focal_method.body: @Override
      public void write(OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options) throws IOException, ResourceFilterException {
          // extracts key value pairs in original sequence order
          List<ResourceString> resStrings = languageBundle.getSortedResourceStrings();
  
          JsonObject output = new JsonObject();
          JsonObject top_level;
  
          if (this instanceof GlobalizeJsResource) {
              String resLanguageCode = languageBundle.getEmbeddedLanguageCode();
              if (resLanguageCode == null || resLanguageCode.isEmpty()) {
                  throw new ResourceFilterException("Missing resource language code in the specified language bundle.");
              }
              top_level = new JsonObject();
              top_level.add(resLanguageCode, output);
          } else {
              top_level = output;
          }
  
          for (ResourceString res : resStrings) {
              String key = res.getKey();
              List<KeyPiece> keyPieces = splitKeyPieces(key);
              JsonElement current = output;
              for (int i = 0; i < keyPieces.size(); i++) {
                  if (i + 1 < keyPieces.size()) { // There is structure under this
                                                  // key piece
                      if (current.isJsonObject()) {
                          JsonObject currentObject = current.getAsJsonObject();
                          if (!currentObject.has(keyPieces.get(i).keyValue)) {
                              if (keyPieces.get(i + 1).keyType == JsonToken.BEGIN_ARRAY) {
                                  currentObject.add(keyPieces.get(i).keyValue, new JsonArray());
                              } else {
                                  currentObject.add(keyPieces.get(i).keyValue, new JsonObject());
                              }
                          }
                          current = currentObject.get(keyPieces.get(i).keyValue);
                      } else {
                          JsonArray currentArray = current.getAsJsonArray();
                          Integer idx = Integer.valueOf(keyPieces.get(i).keyValue);
                          for (int arrayIndex = currentArray.size(); arrayIndex <= idx; arrayIndex++) {
                              currentArray.add(JsonNull.INSTANCE);
                          }
                          if (currentArray.get(idx).isJsonNull()) {
                              if (keyPieces.get(i + 1).keyType == JsonToken.BEGIN_ARRAY) {
                                  currentArray.set(idx, new JsonArray());
                              } else {
                                  currentArray.set(idx, new JsonObject());
                              }
                          }
                          current = currentArray.get(idx);
                      }
                  } else { // This is the leaf node
                      if (keyPieces.get(i).keyType == JsonToken.BEGIN_ARRAY) {
                          JsonArray currentArray = current.getAsJsonArray();
                          Integer idx = Integer.valueOf(keyPieces.get(i).keyValue);
                          JsonPrimitive e = new JsonPrimitive(res.getValue());
                          for (int arrayIndex = currentArray.size(); arrayIndex <= idx; arrayIndex++) {
                              currentArray.add(JsonNull.INSTANCE);
                          }
                          current.getAsJsonArray().set(idx, e);
                      } else {
                          current.getAsJsonObject().addProperty(keyPieces.get(i).keyValue, res.getValue());
                      }
                  }
              }
          }
          try (OutputStreamWriter writer = new OutputStreamWriter(new BufferedOutputStream(outStream),
                  StandardCharsets.UTF_8)) {
              new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create().toJson(top_level, writer);
          }
      }
focal_method.class_method_signature: JsonResource.write(OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_method.full_signature: @Override public void write(OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_method.identifier: write
focal_method.invocations: getSortedResourceStrings getEmbeddedLanguageCode isEmpty add getKey splitKeyPieces size size isJsonObject getAsJsonObject has get get add get add get get get getAsJsonArray valueOf get size add isJsonNull get get set set get get getAsJsonArray valueOf get getValue size add set getAsJsonArray addProperty getAsJsonObject get getValue toJson create disableHtmlEscaping setPrettyPrinting
focal_method.modifiers: @Override public
focal_method.parameters: (OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_method.return: void
focal_method.signature: void write(OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)