當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。