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


Java HttpResponse.getContent方法代码示例

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


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

示例1: getInputStream

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
protected ByteArrayInputStream getInputStream(String endPoint,
                                              Date modifiedAfter,
                                              Map<String, String> params,
                                              String accept) throws IOException {
    OAuthRequestResource req = new OAuthRequestResource(config, signerFactory, endPoint, "GET", null, params, accept);
    req.setToken(token);
    req.setTokenSecret(tokenSecret);
    if (modifiedAfter != null) {
        req.setIfModifiedSince(modifiedAfter);
    }

    try {
        HttpResponse resp = req.execute();

        InputStream is = resp.getContent();

        byte[] bytes = IOUtils.toByteArray(is);

        is.close();
        return new ByteArrayInputStream(bytes);

    } catch (IOException ioe) {
        throw convertException(ioe);
    }
}
 
开发者ID:XeroAPI,项目名称:Xero-Java,代码行数:26,代码来源:XeroClient.java

示例2: parseResponse

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
/**
 * Parse the response from the HTTP call into an instance of the given class.
 *
 * @param response The parsed response object
 * @param c The class to instantiate and use to build the response object
 * @return The ApiResponse object
 * @throws IOException Any IO errors
 */
protected ApiResponse parseResponse(HttpResponse response, Class<?> c) throws IOException {
  ApiResponse res = null;
  InputStream in = response.getContent();

  if (in == null) {
    try {
      res = (ApiResponse)c.newInstance();
    } catch(ReflectiveOperationException e) {
      throw new RuntimeException("Cannot instantiate " + c, e);
    }
  } else {
    try {
      JsonParser jsonParser = GsonFactory.getDefaultInstance().createJsonParser(in);
      res = (ApiResponse)jsonParser.parse(c);
    } finally {
      in.close();
    }
  }

  res.setHttpRequest(response.getRequest());
  res.setHttpResponse(response);

  return res;
}
 
开发者ID:dnsimple,项目名称:dnsimple-java,代码行数:33,代码来源:HttpEndpointClient.java

示例3: get

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
public String get(String url) {
    try {
        HttpRequest request = new NetHttpTransport()
                .createRequestFactory()
                .buildGetRequest(new GenericUrl(url));
        HttpResponse response = request.execute();
        InputStream is = response.getContent();
        StringBuilder sb = new StringBuilder();
        int ch;
        while ((ch = is.read()) != -1) {
            sb.append((char) ch);
        }
        response.disconnect();
        return sb.toString();
    } catch (Exception e) {
        throw new RuntimeException();
    }
}
 
开发者ID:Fewlaps,项目名称:http-monitor,代码行数:19,代码来源:HttpClient.java

示例4: download

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
@Converter
public static InputStream download(com.google.api.services.drive.model.File fileMetadata, Exchange exchange) throws Exception {
    if (fileMetadata.getDownloadUrl() != null && fileMetadata.getDownloadUrl().length() > 0) {
        try {
            // TODO maybe separate this out as custom drive API ex. google-drive://download...
            HttpResponse resp = getClient(exchange).getRequestFactory().buildGetRequest(new GenericUrl(fileMetadata.getDownloadUrl())).execute();
            return resp.getContent();
        } catch (IOException e) {
            LOG.debug("Could not download file.", e);
            return null;
        }
    } else {
        // The file doesn't have any content stored on Drive.
        return null;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:GoogleDriveFilesConverter.java

示例5: getFileContent

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
private InputStream getFileContent(File driveFile, Drive driveService) throws IOException {
	if (driveFile.getDownloadUrl() != null && driveFile.getDownloadUrl().length() > 0) {

		GenericUrl downloadUrl = new GenericUrl(driveFile.getDownloadUrl());

		HttpResponse resp = driveService.getRequestFactory().buildGetRequest(downloadUrl).execute();
		return resp.getContent();
	} else {
		//return an empty input stream
		return new ByteArrayInputStream("".getBytes());
	}

}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:14,代码来源:GoogleDriveFileStorage.java

示例6: lowLevelGetRequest

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
/**
 * An annoying workaround to the issue that some github APi calls
 * are not exposed by egit library
 *
 * @param url
 * @return
 * @throws IOException
 */
private Map<String, Object> lowLevelGetRequest(String url) throws IOException {
    NetHttpTransport transport = new NetHttpTransport.Builder().build();
    HttpRequestFactory requestFactory = transport.createRequestFactory();
    HttpRequest httpRequest = requestFactory.buildGetRequest(new GenericUrl(url));
    HttpResponse execute = httpRequest.execute();
    InputStream content = execute.getContent();
    String s = IOUtils.toString(content, StandardCharsets.UTF_8);
    Gson gson = new Gson();
    Type stringStringMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    return gson.fromJson(s, stringStringMap);
}
 
开发者ID:dockstore,项目名称:write_api_service,代码行数:21,代码来源:GitHubBuilder.java

示例7: createFromGoogleDriveBackup

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
public static DatabaseImport createFromGoogleDriveBackup(Context context, DatabaseAdapter dbAdapter, Drive drive, com.google.api.services.drive.model.File file)
        throws IOException {
    HttpResponse response = drive.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl())).execute();
    InputStream inputStream = response.getContent();
    InputStream in = new GZIPInputStream(inputStream);
    return new DatabaseImport(context, dbAdapter, in);
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:8,代码来源:DatabaseImport.java

示例8: exchangeAuthorizationForToken

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
public OauthToken exchangeAuthorizationForToken(String code, String clientId, String clientSecret, Map<String, Object> options) throws DnsimpleException, IOException {
  Map<String, Object> attributes = new HashMap<String, Object>();
  attributes.put("code", code);
  attributes.put("client_id", clientId);
  attributes.put("client_secret", clientSecret);
  attributes.put("grant_type", "authorization_code");

  if (options.containsKey("state")) {
    attributes.put("state", options.remove("state"));
  }

  if (options.containsKey("redirect_uri")) {
    attributes.put("redirect_uri", options.remove("redirect_uri"));
  }

  HttpResponse response = client.post("oauth/access_token", attributes);
  InputStream in = response.getContent();
  if (in == null) {
    throw new DnsimpleException("Response was empty", null, response.getStatusCode());
  } else {
    try {
      JsonParser jsonParser = GsonFactory.getDefaultInstance().createJsonParser(in);
      return jsonParser.parse(OauthToken.class);
    } finally {
      in.close();
    }
  }
}
 
开发者ID:dnsimple,项目名称:dnsimple-java,代码行数:29,代码来源:OauthEndpoint.java

示例9: postRequest

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
@VisibleForTesting
InputStream postRequest(String url, String boundary, String content) throws IOException {
  HttpRequestFactory requestFactory = new NetHttpTransport().createRequestFactory();
  HttpRequest request = requestFactory.buildPostRequest(new GenericUrl(url),
      ByteArrayContent.fromString("multipart/form-data; boundary=" + boundary, content));
  request.setReadTimeout(60000);  // 60 seconds is the max App Engine request time
  HttpResponse response = request.execute();
  if (response.getStatusCode() >= 300) {
    throw new IOException("Client Generation failed at server side: " + response.getContent());
  } else {
    return response.getContent();
  }
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:14,代码来源:CloudClientLibGenerator.java

示例10: handleResponse

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
@Override
public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry)
    throws IOException {
  System.out.println(response.getStatusCode());
  BufferedReader in = new BufferedReader(new InputStreamReader(response.getContent()));
  String line;
  while ((line = in.readLine()) != null) {
    System.out.println(line);
  }
  return false;
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:12,代码来源:TestUtils.java

示例11: getContentOfFile

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
/**
 * Gets the content of a file on Google Drive.
 * 
 * @param file file to read
 * @param drive a Google Drive object
 * @return the string content of the file
 * @throws IOException
 */
public static String getContentOfFile(File file, Drive drive) throws IOException {
  HttpResponse resp = drive.getRequestFactory()
      .buildGetRequest(new GenericUrl(file.getDownloadUrl())).execute();
  BufferedReader br = new BufferedReader(new InputStreamReader(resp.getContent()));
  StringBuilder sb = new StringBuilder();
  String line;
  while ((line = br.readLine()) != null) {
    sb.append(line);
  }
  String fileContent = sb.toString();
  br.close();
  return fileContent;
}
 
开发者ID:Plonk42,项目名称:mytracks,代码行数:22,代码来源:SyncTestUtils.java

示例12: getFile

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
protected String getFile(String endPoint,
                         Date modifiedAfter,
                         Map<String, String> params,
                         String accept,
                         String dirPath) throws IOException {
    OAuthRequestResource req = new OAuthRequestResource(config, signerFactory, endPoint, "GET", null, params, accept);
    req.setToken(token);
    req.setTokenSecret(tokenSecret);
    if (modifiedAfter != null) {
        req.setIfModifiedSince(modifiedAfter);
    }

    try {
        HttpResponse resp = req.execute();

        InputStream inputStream = resp.getContent();
        List<String> disposition = resp.getHeaders().getHeaderStringValues("Content-Disposition");

        String fileName = null;
        Pattern regex = Pattern.compile("(?<=filename=\").*?(?=\")");
        Matcher regexMatcher = regex.matcher(disposition.toString());
        if (regexMatcher.find()) {
            fileName = regexMatcher.group();
        }

        String saveFilePath = dirPath + File.separator + fileName;
        FileOutputStream outputStream = new FileOutputStream(saveFilePath);

        int bytesRead = -1;
        byte[] buffer = new byte[BUFFER_SIZE];
        while ((bytesRead = inputStream.read(buffer)) != -1) {
            outputStream.write(buffer, 0, bytesRead);
        }
        outputStream.close();
        inputStream.close();

        return saveFilePath;
    } catch (IOException ioe) {
        throw xeroExceptionHandler.convertException(ioe);
    }
}
 
开发者ID:XeroAPI,项目名称:Xero-Java,代码行数:42,代码来源:XeroClient.java

示例13: getThumbnail

import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
/**
 * Recupera la <i>thumbnail</i> del contenuto.
 * <p>
 * Il chiamante dovrebbe invocare {@link InputStream#close} una volta che lo {@link InputStream}
 * resituito non è più necessario. Esempio d'uso:
 *
 * <pre>
 * InputStream is = nodeService.getThumbnail(lContentId, lThumbDefinition, true);
 * try {
 *     // Utilizzo dello stream
 * } finally {
 *     is.close();
 * }
 * </pre>
 * 
 * @param pContentId
 *            L'id del contenuto.
 * @param pThumbDefinition
 *            Il nome della <i>thumbnail</i> desiderata.
 * @param pForceCreate
 *            Se {@code true}, viene richiesta la crazione (sincrona) della <i>thumbnail</i> nel
 *            caso questa non esista.
 * 
 * @return Lo {@link InputStream} della <i>thumbnail</i> richiesta o {@code null} se questa non
 *         esiste.
 * 
 * @throws IOException
 */
public InputStream getThumbnail(String pContentId, String pThumbDefinition, boolean pForceCreate)
        throws IOException {
	/*
	 * GET <base>/content{property}/thumbnails/{thumbnailname}?c={queueforcecreate?}&ph={placeholder?}&lastModified={modified?}
	 * [placeholder e lastModified non gestiti; creazione queued non gestita]
	 */
	GenericUrl lUrl = getContentUrl(pContentId);
	lUrl.appendRawPath(URL_RELATIVE_THUMBNAILS);
	lUrl.getPathParts().add(pThumbDefinition);
	if (pForceCreate) {
		lUrl.set("c", Thumbnail.FORCE_CREATE);
	}

	HttpRequest lRequest = mHttpRequestFactory.buildGetRequest(lUrl);

	HttpResponse lResponse;
	try {
		lResponse = lRequest.execute();

	} catch (HttpResponseException e) {
		// TODO (Alessio) logging e gestione più fine degli errori
		return null;
	}

	InputStream lThumbnailStream = lResponse.getContent();
	return lThumbnailStream;
}
 
开发者ID:MakeITBologna,项目名称:zefiro,代码行数:56,代码来源:NodeService.java


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