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


Java TypedInput.in方法代码示例

本文整理汇总了Java中retrofit.mime.TypedInput.in方法的典型用法代码示例。如果您正苦于以下问题:Java TypedInput.in方法的具体用法?Java TypedInput.in怎么用?Java TypedInput.in使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在retrofit.mime.TypedInput的用法示例。


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

示例1: fromBody

import retrofit.mime.TypedInput; //导入方法依赖的package包/类
@Override public Object fromBody(TypedInput body, Type type) throws ConversionException {
    try {
        InputStream stream = body.in();
        String responseBodyString = MiniIOUtils.toString(stream);
        if(responseBodyString.contains("<!DOCTYPE html>"))
            return responseBodyString;
        JsonParser parser = new JsonParser();
        JsonObject element = (JsonObject)parser.parse(responseBodyString);
        JsonElement dataObject = element.get("data");
        if (!dataObject.isJsonArray() && type instanceof GenericArrayType) {
            Type componentType = ((GenericArrayType) type).getGenericComponentType();
            Class<?> c = Class.forName(getClassName(componentType));
            return Array.newInstance(c, 0);
        }
        return gson.fromJson(dataObject, type);
    } catch (JsonParseException | IOException | ClassNotFoundException e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:crysehillmes,项目名称:smoothnovelreader,代码行数:20,代码来源:CustomGsonConverter.java

示例2: fromBody

import retrofit.mime.TypedInput; //导入方法依赖的package包/类
@Override
public Object fromBody(TypedInput body, Type type) throws ConversionException {
    try {
        InputStream stream = body.in();
        String responseBodyString = MiniIOUtils.toString(stream);
        if (responseBodyString.contains("<!DOCTYPE html>"))
            return responseBodyString;
        JsonParser parser = new JsonParser();
        JsonObject element = (JsonObject) parser.parse(responseBodyString);
        JsonElement dataObject = null;
        if (element.has("items") && !(element.has("labels") && element.has("desc") && element.has("curl"))) {
            dataObject = element.get("items");
        } else {
            dataObject = element;
        }
        if (!dataObject.isJsonArray() && type instanceof GenericArrayType) {
            Type componentType = ((GenericArrayType) type).getGenericComponentType();
            Class<?> c = Class.forName(getClassName(componentType));
            return Array.newInstance(c, 0);
        }
        return gson.fromJson(dataObject, type);
    } catch (JsonParseException | IOException | ClassNotFoundException e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:crysehillmes,项目名称:smoothnovelreader,代码行数:26,代码来源:CustomGsonConverter.java

示例3: fromBody

import retrofit.mime.TypedInput; //导入方法依赖的package包/类
@Override
public Object fromBody(TypedInput body, Type type) throws ConversionException {
    boolean willCloseStream = false; // try to close the stream, if there is no exception thrown
                                     // using tolerant JsonReader
    try {
        JsonReader jsonReader = new JsonReader(new InputStreamReader(body.in()));
        jsonReader.setLenient(true);
        Object o = mGson.fromJson(jsonReader, type);
        willCloseStream = true;
        return o;
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (willCloseStream) {
            closeStream(body);
        }
    }

    return super.fromBody(body, type);
}
 
开发者ID:bwzz,项目名称:yyl,代码行数:21,代码来源:MyGsonConvertor.java

示例4: fromBody

import retrofit.mime.TypedInput; //导入方法依赖的package包/类
@Override
public Object fromBody(TypedInput typedInput, Type type) throws ConversionException {
    String text = null;
    try {
        typedInput.in();
        BufferedReader reader = new BufferedReader(new InputStreamReader(typedInput.in()));
        StringBuilder out = new StringBuilder();
        String newLine = System.getProperty("line.separator");
        String line;
        while ((line = reader.readLine()) != null) {
            out.append(line);
            out.append(newLine);
        }
        text = out.toString();
    } catch (IOException ignored) {/*NOP*/ }
    return text;
}
 
开发者ID:percolate,项目名称:foam,代码行数:18,代码来源:GoogleAnalytics.java

示例5: readInputStream

import retrofit.mime.TypedInput; //导入方法依赖的package包/类
static String readInputStream(TypedInput in) {
    StringBuilder builder = new StringBuilder();
    try {
        BufferedReader bufferedStream
                = new BufferedReader(new InputStreamReader(in.in()));
        try {
            String line;
            while ((line = bufferedStream.readLine()) != null) {
                builder.append(line);
                builder.append('\n');
            }
            return builder.toString();
        } finally {
            bufferedStream.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return builder.toString();
}
 
开发者ID:dhis2,项目名称:dhis2-android-dashboard,代码行数:21,代码来源:WebViewFragment.java

示例6: fromBody

import retrofit.mime.TypedInput; //导入方法依赖的package包/类
@Override
public Object fromBody(TypedInput body, Type type) throws ConversionException {
    String charset = "UTF-8";
    if (body.mimeType() != null) {
        charset = MimeUtil.parseCharset(body.mimeType());
    }
    InputStreamReader isr = null;
    try {
        isr = new InputStreamReader(body.in(), charset);
        return gson.fromJson(isr, type);
    } catch (IOException | JsonParseException e) {
        throw new ConversionException(e);
    } finally {
        if (isr != null) {
            try {
                isr.close();
            } catch (IOException ex) {
                // Ignored
            }
        }
    }
}
 
开发者ID:phil-lopreiato,项目名称:tba-apiv2-java,代码行数:23,代码来源:RetrofitConverter.java

示例7: fromBody

import retrofit.mime.TypedInput; //导入方法依赖的package包/类
@Override
public Object fromBody(TypedInput typedInput, Type type) throws ConversionException {
    JavaType javaType = objectMapper.getTypeFactory().constructType(type);

    try {
        InputStream in = typedInput.in();
        try {
            return objectMapper.readValue(in, javaType);
        } finally {
             if (in != null) {
                 in.close();
             }
        }


    } catch (IOException e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:AAverin,项目名称:android-skeleton-project,代码行数:20,代码来源:JacksonConverter.java

示例8: fromBody

import retrofit.mime.TypedInput; //导入方法依赖的package包/类
@Override
public Object fromBody(TypedInput body, Type type) throws ConversionException {
    String charset = "UTF-8";
    if (body.mimeType() != null) {
        charset = MimeUtil.parseCharset(body.mimeType());
    }

    InputStreamReader isr = null;
    try {
        isr = new InputStreamReader(body.in(), charset);

        // Need a Class instance here, as using the Type in serializer.read(...) doesn't work
        Class<?> typeClass = (Class<?>) type;

        return serializer.read((Class<?>) type, isr);
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:aegis123,项目名称:retrofit-simplexmlconverter,代码行数:20,代码来源:SimpleXmlConverter.java

示例9: closeStream

import retrofit.mime.TypedInput; //导入方法依赖的package包/类
private void closeStream(TypedInput body) {
    try {
        InputStream in = body.in();
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:bwzz,项目名称:yyl,代码行数:9,代码来源:MyGsonConvertor.java

示例10: getString

import retrofit.mime.TypedInput; //导入方法依赖的package包/类
private String getString(TypedInput body) throws ConversionException {
    String charset = CHARSET_DEFAULT;
    if (body.mimeType() != null) {
        charset = MimeUtil.parseCharset(body.mimeType(), charset);
    }
    InputStreamReader isr = null;
    String result;
    try {
        isr = new InputStreamReader(body.in(), charset);
        StringBuilder sb = new StringBuilder();
        char[] buf = new char[BUFFER_SIZE];
        for (; ; ) {
            int res = isr.read(buf, 0, buf.length);
            if (res < 0) {
                break;
            }
            sb.append(buf, 0, res);
        }
        result = sb.toString();
        return result;
    } catch (IOException e) {
        throw new ConversionException(e);
    } finally {
        if (isr != null) {
            try {
                isr.close();
            } catch (IOException ignored) {
            }
        }
    }
}
 
开发者ID:Jude95,项目名称:Fishing,代码行数:32,代码来源:WrapperConverter.java

示例11: ExceptionCatchingTypedInput

import retrofit.mime.TypedInput; //导入方法依赖的package包/类
ExceptionCatchingTypedInput(TypedInput delegate) throws IOException {
    this.delegate = delegate;
    this.delegateStream = new ExceptionCatchingInputStream(delegate.in());
}
 
开发者ID:goodev,项目名称:android-discourse,代码行数:5,代码来源:ExceptionCatchingTypedInput.java

示例12: ExceptionCatchingTypedInput

import retrofit.mime.TypedInput; //导入方法依赖的package包/类
ExceptionCatchingTypedInput(TypedInput delegate) throws IOException
{
  this.delegate = delegate;
  this.delegateStream = new ExceptionCatchingInputStream(delegate.in());
}
 
开发者ID:toadzky,项目名称:retrofit-jaxrs,代码行数:6,代码来源:ExceptionCatchingTypedInput.java

示例13: fromBody

import retrofit.mime.TypedInput; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") //
@Override
public Object fromBody(TypedInput body, Type type) throws ConversionException
{
  if (!(type instanceof Class<?>))
  {
    throw new IllegalArgumentException("Expected a raw Class<?> but was " + type);
  }
  Class<?> c = (Class<?>) type;
  if (!Message.class.isAssignableFrom(c))
  {
    throw new IllegalArgumentException("Expected a proto message but was " + c.getName());
  }

  if (!MIME_TYPE.equalsIgnoreCase(body.mimeType()))
  {
    throw new IllegalArgumentException("Expected a proto but was: " + body.mimeType());
  }

  InputStream in = null;
  try
  {
    in = body.in();
    return wire.parseFrom(in, (Class<Message>) c);
  }
  catch (IOException e)
  {
    throw new ConversionException(e);
  }
  finally
  {
    if (in != null)
    {
      try
      {
        in.close();
      }
      catch (IOException ignored)
      {
      }
    }
  }
}
 
开发者ID:toadzky,项目名称:retrofit-jaxrs,代码行数:44,代码来源:WireConverter.java


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