当前位置: 首页>>代码示例>>Java>>正文


Java Streams类代码示例

本文整理汇总了Java中com.google.gson.internal.Streams的典型用法代码示例。如果您正苦于以下问题:Java Streams类的具体用法?Java Streams怎么用?Java Streams使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Streams类属于com.google.gson.internal包,在下文中一共展示了Streams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseEvent

import com.google.gson.internal.Streams; //导入依赖的package包/类
public static Event parseEvent(byte[] event) {
  //parse the event payload and remove the type attribute
  JsonReader jsonReader =  new JsonReader(new InputStreamReader(new ByteArrayInputStream(event)));
  JsonElement jsonElement = Streams.parse(jsonReader);
  JsonElement labelJsonElement = jsonElement.getAsJsonObject().remove(TYPE_FIELD);

  if (labelJsonElement == null) {
    throw new IllegalArgumentException("Event does not define a type field: " + new String(event));
  }

  //convert json to POJO, based on the type attribute
  switch (labelJsonElement.getAsString()) {
    case "watermark":
      return gson.fromJson(jsonElement, WatermarkEvent.class);
    case "trip":
      return gson.fromJson(jsonElement, TripEvent.class);
    default:
      throw new IllegalArgumentException("Found unsupported event type: " + labelJsonElement.getAsString());
  }
}
 
开发者ID:awslabs,项目名称:flink-stream-processing-refarch,代码行数:21,代码来源:Event.java

示例2: toJson

import com.google.gson.internal.Streams; //导入依赖的package包/类
public void toJson(JsonElement jsonElement, JsonWriter writer) throws JsonIOException {
    boolean oldLenient = writer.isLenient();
    writer.setLenient(true);
    boolean oldHtmlSafe = writer.isHtmlSafe();
    writer.setHtmlSafe(this.htmlSafe);
    boolean oldSerializeNulls = writer.getSerializeNulls();
    writer.setSerializeNulls(this.serializeNulls);
    try {
        Streams.write(jsonElement, writer);
        writer.setLenient(oldLenient);
        writer.setHtmlSafe(oldHtmlSafe);
        writer.setSerializeNulls(oldSerializeNulls);
    } catch (Throwable e) {
        throw new JsonIOException(e);
    } catch (Throwable th) {
        writer.setLenient(oldLenient);
        writer.setHtmlSafe(oldHtmlSafe);
        writer.setSerializeNulls(oldSerializeNulls);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:21,代码来源:Gson.java

示例3: toJson

import com.google.gson.internal.Streams; //导入依赖的package包/类
/**
 * Writes the JSON for {@code jsonElement} to {@code writer}.
 * @throws JsonIOException if there was a problem writing to the writer
 */
public void toJson(JsonElement jsonElement, JsonWriter writer) throws JsonIOException {
  boolean oldLenient = writer.isLenient();
  writer.setLenient(true);
  boolean oldHtmlSafe = writer.isHtmlSafe();
  writer.setHtmlSafe(htmlSafe);
  boolean oldSerializeNulls = writer.getSerializeNulls();
  writer.setSerializeNulls(serializeNulls);
  try {
    Streams.write(jsonElement, writer);
  } catch (IOException e) {
    throw new JsonIOException(e);
  } finally {
    writer.setLenient(oldLenient);
    writer.setHtmlSafe(oldHtmlSafe);
    writer.setSerializeNulls(oldSerializeNulls);
  }
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:22,代码来源:Gson.java

示例4: read

import com.google.gson.internal.Streams; //导入依赖的package包/类
@Override
public Type read(JsonReader in) throws IOException {
    JsonElement jsonElement = Streams.parse(in);
    JsonElement typeValueJsonElement = jsonElement.getAsJsonObject().remove("type");
    if (typeValueJsonElement == null || typeValueJsonElement.isJsonNull()) {
        throw new JsonParseException("cannot deserialize generator.standard.polymorphism.Type because the subtype field 'type' is either null or does not exist.");
    }
    java.lang.String value = typeValueJsonElement.getAsString();
    TypeAdapter<? extends generator.standard.polymorphism.Type> delegate = typeAdaptersDelegatedByValueMap.get(value);
    if (delegate == null) {
        throw new GsonSubTypeFailureException("Failed to find subtype for value: " + value);
    }
    generator.standard.polymorphism.Type result = delegate.fromJsonTree(jsonElement);
    if (result == null) {
        throw new GsonSubTypeFailureException("Failed to deserailize subtype for object: " + jsonElement);
    }
    return result;
}
 
开发者ID:LachlanMcKee,项目名称:gsonpath,代码行数:19,代码来源:TypesList_GsonTypeAdapter.java

示例5: read

import com.google.gson.internal.Streams; //导入依赖的package包/类
@Override
public Type read(JsonReader in) throws IOException {
    JsonElement jsonElement = Streams.parse(in);
    JsonElement typeValueJsonElement = jsonElement.getAsJsonObject().remove("type");
    if (typeValueJsonElement == null || typeValueJsonElement.isJsonNull()) {
        throw new JsonParseException("cannot deserialize generator.standard.polymorphism.Type because the subtype field 'type' is either null or does not exist.");
    }
    java.lang.String value = typeValueJsonElement.getAsString();
    TypeAdapter<? extends generator.standard.polymorphism.Type> delegate = typeAdaptersDelegatedByValueMap.get(value);
    if (delegate == null) {
        // Use the default type adapter if the type is unknown.
        delegate = defaultTypeAdapterDelegate;
    }
    generator.standard.polymorphism.Type result = delegate.fromJsonTree(jsonElement);
    return result;
}
 
开发者ID:LachlanMcKee,项目名称:gsonpath,代码行数:17,代码来源:TypesList_GsonTypeAdapter.java

示例6: onMessage

import com.google.gson.internal.Streams; //导入依赖的package包/类
@SuppressWarnings("unused")
@OnMessage
public void onMessage(ByteBuffer message, Session session) {
    HillviewLogger.instance.info("New message from client",
            "{0}", session.getId());
    RpcRequest req;
    try {
        ByteArrayInputStream stream = new ByteArrayInputStream(message.array());
        InflaterInputStream decompressed = new InflaterInputStream(stream);
        Reader reader = new InputStreamReader(decompressed);
        JsonReader jReader = new JsonReader(reader);
        JsonElement elem = Streams.parse(jReader);
        HillviewLogger.instance.info("Decoded message", "{0}", elem.toString());
        req = new RpcRequest(elem);
        if (RpcObjectManager.instance.getTarget(session) != null)
            throw new RuntimeException("Session already associated with a request!");
    } catch (Exception ex) {
        HillviewLogger.instance.error("Error processing json", ex);
        this.replyWithError(ex, session);
        return;
    }

    RpcRequestContext context = new RpcRequestContext(session);
    RpcServer.execute(req, context);
}
 
开发者ID:vmware,项目名称:hillview,代码行数:26,代码来源:RpcServer.java

示例7: load

import com.google.gson.internal.Streams; //导入依赖的package包/类
public ITable load() {
    Schema schema = null;
    if (this.schemaPath != null)
        schema = Schema.readFromJsonFile(Paths.get(this.schemaPath));

    Reader file = this.getFileReader();
    JsonReader jReader = new JsonReader(file);
    JsonElement elem = Streams.parse(jReader);
    if (!elem.isJsonArray())
        throw new RuntimeException("Expected a JSON array in file " + filename);
    JsonArray array = elem.getAsJsonArray();
    if (array.size() == 0 && schema == null)
        throw new RuntimeException("Empty JSON array in file " + filename);

    if (schema == null)
        schema = this.guessSchema(filename, array);
    IAppendableColumn[] columns = schema.createAppendableColumns();

    this.currentRow = 0;
    for (JsonElement e : array)
        this.append(columns, e);

    return new Table(columns);
}
 
开发者ID:vmware,项目名称:hillview,代码行数:25,代码来源:JsonFileLoader.java

示例8: read

import com.google.gson.internal.Streams; //导入依赖的package包/类
public final T read(JsonReader paramJsonReader)
  throws IOException
{
  if (this.deserializer == null) {
    return delegate().read(paramJsonReader);
  }
  JsonElement localJsonElement = Streams.parse(paramJsonReader);
  if ((localJsonElement instanceof JsonNull)) {
    return null;
  }
  try
  {
    JsonDeserializer localJsonDeserializer = this.deserializer;
    Type localType = this.typeToken.type;
    Object localObject = localJsonDeserializer.deserialize$140ae884(localJsonElement, localType);
    return localObject;
  }
  catch (JsonParseException localJsonParseException)
  {
    throw localJsonParseException;
  }
  catch (Exception localException)
  {
    throw new JsonParseException(localException);
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:27,代码来源:TreeTypeAdapter.java

示例9: write

import com.google.gson.internal.Streams; //导入依赖的package包/类
public final void write(JsonWriter paramJsonWriter, T paramT)
  throws IOException
{
  if (this.serializer == null)
  {
    delegate().write(paramJsonWriter, paramT);
    return;
  }
  if (paramT == null)
  {
    paramJsonWriter.nullValue();
    return;
  }
  JsonSerializer localJsonSerializer = this.serializer;
  Streams.write(localJsonSerializer.serialize$117eb95b(paramT), paramJsonWriter);
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:17,代码来源:TreeTypeAdapter.java

示例10: toString

import com.google.gson.internal.Streams; //导入依赖的package包/类
public String toString()
{
  try
  {
    StringWriter localStringWriter = new StringWriter();
    JsonWriter localJsonWriter = new JsonWriter(localStringWriter);
    localJsonWriter.lenient = true;
    Streams.write(this, localJsonWriter);
    String str = localStringWriter.toString();
    return str;
  }
  catch (IOException localIOException)
  {
    throw new AssertionError(localIOException);
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:17,代码来源:JsonElement.java

示例11: toString

import com.google.gson.internal.Streams; //导入依赖的package包/类
public String toString()
{
    String s;
    try
    {
        StringWriter stringwriter = new StringWriter();
        JsonWriter jsonwriter = new JsonWriter(stringwriter);
        jsonwriter.setLenient(true);
        Streams.write(this, jsonwriter);
        s = stringwriter.toString();
    }
    catch (IOException ioexception)
    {
        throw new AssertionError(ioexception);
    }
    return s;
}
 
开发者ID:vishnudevk,项目名称:MiBandDecompiled,代码行数:18,代码来源:JsonElement.java

示例12: write

import com.google.gson.internal.Streams; //导入依赖的package包/类
public void write(JsonWriter jsonwriter, Object obj)
{
    if (a == null)
    {
        a().write(jsonwriter, obj);
        return;
    }
    if (obj == null)
    {
        jsonwriter.nullValue();
        return;
    } else
    {
        Streams.write(a.serialize(obj, d.getType(), c.c), jsonwriter);
        return;
    }
}
 
开发者ID:vishnudevk,项目名称:MiBandDecompiled,代码行数:18,代码来源:o.java

示例13: getJsapiTicket

import com.google.gson.internal.Streams; //导入依赖的package包/类
public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
  if (forceRefresh) {
    wxCpConfigStorage.expireJsapiTicket();
  }
  if (wxCpConfigStorage.isJsapiTicketExpired()) {
    synchronized (globalJsapiTicketRefreshLock) {
      if (wxCpConfigStorage.isJsapiTicketExpired()) {
        String url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket";
        String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
        JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
        JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
        String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
        int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
        wxCpConfigStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds);
      }
    }
  }
  return wxCpConfigStorage.getJsapiTicket();
}
 
开发者ID:danileyang,项目名称:mmp,代码行数:20,代码来源:WxCpServiceImpl.java

示例14: userList

import com.google.gson.internal.Streams; //导入依赖的package包/类
@Override
public List<WxCpUser> userList(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException {
  String url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?department_id=" + departId;
  String params = "";
  if (fetchChild != null) {
    params += "&fetch_child=" + (fetchChild ? "1" : "0");
  }
  if (status != null) {
    params += "&status=" + status;
  } else {
    params += "&status=0";
  }

  String responseContent = get(url, params);
  JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
  return WxCpGsonBuilder.INSTANCE.create()
      .fromJson(
          tmpJsonElement.getAsJsonObject().get("userlist"),
          new TypeToken<List<WxCpUser>>() { }.getType()
      );
}
 
开发者ID:danileyang,项目名称:mmp,代码行数:22,代码来源:WxCpServiceImpl.java

示例15: departGetUsers

import com.google.gson.internal.Streams; //导入依赖的package包/类
@Override
public List<WxCpUser> departGetUsers(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException {
  String url = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?department_id=" + departId;
  String params = "";
  if (fetchChild != null) {
    params += "&fetch_child=" + (fetchChild ? "1" : "0");
  }
  if (status != null) {
    params += "&status=" + status;
  } else {
    params += "&status=0";
  }

  String responseContent = get(url, params);
  JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
  return WxCpGsonBuilder.INSTANCE.create()
      .fromJson(
          tmpJsonElement.getAsJsonObject().get("userlist"),
          new TypeToken<List<WxCpUser>>() { }.getType()
      );
}
 
开发者ID:danileyang,项目名称:mmp,代码行数:22,代码来源:WxCpServiceImpl.java


注:本文中的com.google.gson.internal.Streams类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。