Reads and parses a workspace definition from a JSON document.

@param reader    a Reader on top of the workspace definition
@return          a Workspace object
@throws WorkspaceReaderException     if something goes wrong
345910
public Workspace read(Reader reader) throws WorkspaceReaderException {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
            objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

            Workspace workspace = objectMapper.readValue(reader, Workspace.class);
            workspace.hydrate();

            return workspace;
        } catch (IOException ioe) {
            throw new WorkspaceReaderException("Could not read JSON", ioe);
        }
    }
127885
public static Value parse(Reader reader) throws JSONException {
		try {
			return new Parser(reader).parse();
		}
		finally {
			try {
				reader.close();
			}
			catch (IOException e) {
			}
		}
	}
1278830
public Object parse(Reader reader) {
        Object content;

        JsonLexer lexer = new JsonLexer(reader);

        JsonToken token = lexer.nextToken();
        if (token.getType() == OPEN_CURLY) {
            content = parseObject(lexer);
        } else if (token.getType() == OPEN_BRACKET) {
            content = parseArray(lexer);
        } else {
            throw new JsonException(
                    "A JSON payload should start with " + OPEN_CURLY.getLabel() +
                            " or " + OPEN_BRACKET.getLabel() + ".\n" +
                            "Instead, '" + token.getText() + "' was found " +
                            "on line: " + token.getStartLine() + ", " +
                            "column: " + token.getStartColumn()
            );
        }

        return content;
    }
14361
public static Object[] parse(Reader reader, Class<?>[] types,
                                 Converter<Object, Map<String, Object>> mc) throws IOException,
            ParseException {
        return (Object[]) parse(reader, new JSONVisitor(types,
                new JSONValue(mc)), JSONToken.LSQUARE);
    }
551371
public static TsurgeonPattern getTsurgeonOperationsFromReader(BufferedReader reader) throws IOException {
    List<TsurgeonPattern> operations = new ArrayList<TsurgeonPattern>();
    for (String thisLine; (thisLine = reader.readLine()) != null; ) {
      if (emptyLinePattern.matcher(thisLine).matches()) {
        break;
      }
      thisLine = removeComments(thisLine);
      if (emptyLinePattern.matcher(thisLine).matches()) {
        continue;
      }
      // System.err.println("Read tsurgeon op: " + thisLine);
      operations.add(parseOperation(thisLine));
    }
    return collectOperations(operations);
  }
613373
public JsonReader createReader(Reader reader) {
        return new JsonReader(reader, jsonObjectFactory, jsonArrayFactory, objectMapper, typeAdapters);
    }
928745
public DataSources parse(XMLStreamReader reader) throws Exception
   {
      DataSources dataSources = null;

      //iterate over tags
      int iterate;
      try
      {
         iterate = reader.nextTag();
      }
      catch (XMLStreamException e)
      {
         //found a non tag..go on. Normally non-tag found at beginning are comments or DTD declaration
         iterate = reader.nextTag();
      }
      switch (iterate)
      {
         case END_ELEMENT : {
            // should mean we're done, so ignore it.
            break;
         }
         case START_ELEMENT : {

            switch (reader.getLocalName())
            {
               case XML.ELEMENT_DATASOURCES : {
                  dataSources = parseDataSources(reader);
                  break;
               }
               default :
                  throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
            }

            break;
         }
         default :
            throw new IllegalStateException();
      }

      return dataSources;

   }
877959
public static HostsFileEntries parse(Reader reader) throws IOException {
        checkNotNull(reader, "reader");
        BufferedReader buff = new BufferedReader(reader);
        try {
            Map<String, Inet4Address> ipv4Entries = new HashMap<String, Inet4Address>();
            Map<String, Inet6Address> ipv6Entries = new HashMap<String, Inet6Address>();
            String line;
            while ((line = buff.readLine()) != null) {
                // remove comment
                int commentPosition = line.indexOf('#');
                if (commentPosition != -1) {
                    line = line.substring(0, commentPosition);
                }
                // skip empty lines
                line = line.trim();
                if (line.isEmpty()) {
                    continue;
                }

                // split
                List<String> lineParts = new ArrayList<String>();
                for (String s: WHITESPACES.split(line)) {
                    if (!s.isEmpty()) {
                        lineParts.add(s);
                    }
                }

                // a valid line should be [IP, hostname, alias*]
                if (lineParts.size() < 2) {
                    // skip invalid line
                    continue;
                }

                byte[] ipBytes = NetUtil.createByteArrayFromIpAddressString(lineParts.get(0));

                if (ipBytes == null) {
                    // skip invalid IP
                    continue;
                }

                // loop over hostname and aliases
                for (int i = 1; i < lineParts.size(); i ++) {
                    String hostname = lineParts.get(i);
                    String hostnameLower = hostname.toLowerCase(Locale.ENGLISH);
                    InetAddress address = InetAddress.getByAddress(hostname, ipBytes);
                    if (address instanceof Inet4Address) {
                        Inet4Address previous = ipv4Entries.put(hostnameLower, (Inet4Address) address);
                        if (previous != null) {
                            // restore, we want to keep the first entry
                            ipv4Entries.put(hostnameLower, previous);
                        }
                    } else {
                        Inet6Address previous = ipv6Entries.put(hostnameLower, (Inet6Address) address);
                        if (previous != null) {
                            // restore, we want to keep the first entry
                            ipv6Entries.put(hostnameLower, previous);
                        }
                    }
                }
            }
            return ipv4Entries.isEmpty() && ipv6Entries.isEmpty() ?
                    HostsFileEntries.EMPTY :
                    new HostsFileEntries(ipv4Entries, ipv6Entries);
        } finally {
            try {
                buff.close();
            } catch (IOException e) {
                logger.warn("Failed to close a reader", e);
            }
        }
    }
1207626
@Override
  public Distance read(JsonReader reader) throws IOException {
    if (reader.peek() == JsonToken.NULL) {
      reader.nextNull();
      return null;
    }

    Distance distance = new Distance();

    reader.beginObject();
    while (reader.hasNext()) {
      String name = reader.nextName();
      if (name.equals("text")) {
        distance.humanReadable = reader.nextString();
      } else if (name.equals("value")) {
        distance.inMeters = reader.nextLong();
      }
    }
    reader.endObject();

    return distance;
  }
1335479
protected WorkManagerSecurity parseWorkManagerSecurity(XMLStreamReader reader) throws XMLStreamException,
      ParserException, ValidateException
   {
      boolean mappingRequired = false;
      String domain = null;
      String defaultPrincipal = null;
      List<String> defaultGroups = null;
      Map<String, String> userMappings = null;
      Map<String, String> groupMappings = null;

      boolean userMappingEnabled = false;

      HashMap<String, String> expressions = new HashMap<String, String>();

      while (reader.hasNext())
      {
         switch (reader.nextTag())
         {
            case END_ELEMENT : {
               if (CommonXML.ELEMENT_WORKMANAGER_SECURITY.equals(reader.getLocalName()))
               {
                  return new WorkManagerSecurityImpl(mappingRequired, domain,
                                                     defaultPrincipal, defaultGroups,
                                                     userMappings, groupMappings,
                          !expressions.isEmpty() ? expressions : null);
               }
               else
               {
                  switch (reader.getLocalName())
                  {
                     case CommonXML.ELEMENT_DEFAULT_GROUPS :
                     case CommonXML.ELEMENT_MAPPINGS :
                     case CommonXML.ELEMENT_MAPPING_REQUIRED :
                     case CommonXML.ELEMENT_DOMAIN :
                     case CommonXML.ELEMENT_DEFAULT_PRINCIPAL :
                     case CommonXML.ELEMENT_GROUP :
                     case CommonXML.ELEMENT_USERS :
                     case CommonXML.ELEMENT_GROUPS :
                     case CommonXML.ELEMENT_MAP :
                        break;
                     default :
                        throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
                  }
               }
               break;
            }
            case START_ELEMENT : {
               switch (reader.getLocalName())
               {
                  case CommonXML.ELEMENT_DEFAULT_GROUPS :
                  case CommonXML.ELEMENT_MAPPINGS : {
                     // Skip
                     break;
                  }
                  case CommonXML.ELEMENT_MAPPING_REQUIRED : {
                     mappingRequired = elementAsBoolean(reader, CommonXML.ELEMENT_MAPPING_REQUIRED, expressions);
                     break;
                  }
                  case CommonXML.ELEMENT_DOMAIN : {
                     domain = elementAsString(reader, CommonXML.ELEMENT_DOMAIN, expressions);
                     break;
                  }
                  case CommonXML.ELEMENT_DEFAULT_PRINCIPAL : {
                     defaultPrincipal = elementAsString(reader, CommonXML.ELEMENT_DEFAULT_PRINCIPAL, expressions);
                     break;
                  }
                  case CommonXML.ELEMENT_GROUP : {
                     if (defaultGroups == null)
                        defaultGroups = new ArrayList<String>(1);

                     defaultGroups.add(elementAsString(reader,
                                                       getExpressionKey(CommonXML.ELEMENT_GROUP,
                                                                        Integer.toString(defaultGroups.size())),
                                                       expressions));
                     break;
                  }
                  case CommonXML.ELEMENT_USERS : {
                     userMappingEnabled = true;
                     break;
                  }
                  case CommonXML.ELEMENT_GROUPS : {
                     userMappingEnabled = false;
                     break;
                  }
                  case CommonXML.ELEMENT_MAP : {
                     if (userMappingEnabled)
                     {
                        if (userMappings == null)
                           userMappings = new HashMap<String, String>();

                        String from = attributeAsString(reader, CommonXML.ATTRIBUTE_FROM, expressions);

                        if (from == null || from.trim().equals(""))
                           throw new ParserException(
                              bundle.requiredAttributeMissing(CommonXML.ATTRIBUTE_FROM,
                                                              reader.getLocalName()));

                        String to = attributeAsString(reader, CommonXML.ATTRIBUTE_TO, expressions);

                        if (to == null || to.trim().equals(""))
                           throw new ParserException(
                              bundle.requiredAttributeMissing(CommonXML.ATTRIBUTE_TO,
                                                              reader.getLocalName()));

                        userMappings.put(from, to);
                     }
                     else
                     {
                        if (groupMappings == null)
                           groupMappings = new HashMap<String, String>();

                        String from = attributeAsString(reader, CommonXML.ATTRIBUTE_FROM, expressions);

                        if (from == null || from.trim().equals(""))
                           throw new ParserException(
                              bundle.requiredAttributeMissing(CommonXML.ATTRIBUTE_FROM,
                                                              reader.getLocalName()));

                        String to = attributeAsString(reader, CommonXML.ATTRIBUTE_TO, expressions);

                        if (to == null || to.trim().equals(""))
                           throw new ParserException(
                              bundle.requiredAttributeMissing(CommonXML.ATTRIBUTE_TO,
                                                              reader.getLocalName()));

                        groupMappings.put(from, to);
                     }
                     break;
                  }
                  default :
                     throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
               }
               break;
            }
         }
      }
      throw new ParserException(bundle.unexpectedEndOfDocument());
   }
95011
public static ObjectReader init(ObjectReader reader) {
        return reader.withAttribute(ATTR_STRING_CACHE, new DeserializerStringCache(
                new HashMap<CharBuffer, String>(2048), new LinkedHashMap<CharBuffer, String>(4096, 0.75f, true) {
                    @Override
                    protected boolean removeEldestEntry(Entry<CharBuffer, String> eldest) {
                        return size() > LRU_LIMIT;
                    }

                }));
    }
143408
@Override
  public SpeechWordConfidence read(JsonReader reader) throws IOException {
    if (reader.peek() == JsonToken.NULL) {
      reader.nextNull();
      return null;
    }

    final SpeechWordConfidence speechWordConfidence = new SpeechWordConfidence();
    reader.beginArray();

    if (reader.peek() == JsonToken.STRING) {
      speechWordConfidence.setWord(reader.nextString());
    }
    if (reader.peek() == JsonToken.NUMBER) {
      speechWordConfidence.setConfidence(reader.nextDouble());
    }

    reader.endArray();
    return speechWordConfidence;
  }
536472
public void parse(Reader reader) throws IOException {
        mScanner = new Scanner(reader);

        mScanner.addErrorListener(new ErrorListener() {
            public void parseError(ErrorEvent e) {
                dispatchParseError(e);
            }
        });

        try {
            parseProperties();
        }
        finally {
            mScanner.close();
        }
    }
896148
public static String read(Reader reader) {
        StringWriter writer = new StringWriter();
        try {
            char[] buffer = new char[DEFAULT_BUFFER_SIZE];
            int n;
            while (-1 != (n = reader.read(buffer))) {
                writer.write(buffer, 0, n);
            }

            return writer.toString();
        } catch (IOException ex) {
            throw new IllegalStateException("read error", ex);
        }
    }
673728
public V deserialize( JsonReader reader, JsonDeserializationContext ctx ) {
        return getDeserializer().deserialize( reader, ctx, getParameters() );
    }
179777
public T parse(Reader reader) throws IOException {
    T bean = createBean();
    populate(bean, reader);
    return bean;
  }
142036
public TypeDefinitionRegistry parse(Reader reader) throws SchemaProblem {
        try (Reader input = reader) {
            return parseImpl(input);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }