java http 读头文件_java – HTTP Get:只下载头文件? (HEAD不支持)

本文介绍了一种通过HTTP请求仅获取响应标头而不下载文件内容的方法。作者在使用HttpGet请求下载文件时遇到了问题,即如何避免下载整个文件内容而只获取HTTP响应标头。文章探讨了现有的代码实现并提出了解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在我的代码中,我使用一些Http Get请求来将一些文件作为流来下载.我使用以下代码:

public String getClassName(String url) throws ClientProtocolException,IOException {

HttpResponse response = sendGetRequestJsonText(url);

Header[] all = response.getAllHeaders();

for (Header h : all) {

System.out.println(h.getName() + ": " + h.getValue());

}

Header[] headers = response.getHeaders("Content-Disposition");

InputStreamParser.convertStreamToString(response.getEntity().getContent());

String result = "";

for (Header header : headers) {

result = header.getValue();

}

return result.substring(result.indexOf("''") + "''".length(),result.length()).trim();

}

但是这会下载响应的全部内容.我想仅检索没有内容的HTTP标头. HEAD请求似乎不起作用,因为我得到状态501,没有实现.我怎样才能做到这一点?

(rmats) [stu4@localhost :~]$ echo -e "/home/stu4/SRR5476912_sorted.bam\n/home/stu4/SRR5476913_sorted.bam" > ./bam_list1.txt (rmats) [stu4@localhost :~]$ echo -e "/home/stu4/SRR5476914_sorted.bam\n/home/stu4/SRR5476915_sorted.bam" > ./bam_list2.txt (rmats) [stu4@localhost :~]$ cat ./bam_list1.txt /home/stu4/SRR5476912_sorted.bam /home/stu4/SRR5476913_sorted.bam (rmats) [stu4@localhost :~]$ cat ./bam_list2.txt /home/stu4/SRR5476914_sorted.bam /home/stu4/SRR5476915_sorted.bam (rmats) [stu4@localhost :~]$ /opt/Anaconda3/envs/rmats/bin/rmats.py \ > --b1 ./bam_list1.txt \ > --b2 ./bam_list2.txt \ > --gtf /home/stu4/Mus_musculus.GRCm38.102.chr.gtf \ > --od /home/stu4/rMATS_output/outs \ > --tmp /home/stu4/rMATS_output/tmp \ > -t paired \ > --readLength 115 \ > --cstat 0.05 \ > --libType fr-unstranded \ > --nthread 4 \ > --tstat 2 gtf: 22.1770730019 There are 55401 distinct gene ID in the gtf file There are 142604 distinct transcript ID in the gtf file There are 34279 one-transcript genes in the gtf file There are 843402 exons in the gtf file There are 26950 one-exon transcripts in the gtf file There are 21842 one-transcript genes with only one exon in the transcript Average number of transcripts per gene is 2.574033 Average number of exons per transcript is 5.914294 Average number of exons per transcript excluding one-exon tx is 7.059436 Average number of gene per geneGroup is 7.464226 statistic: 0.0235040187836 Fail to open /home/stu4/SRR5476912_sorted.bam /home/stu4/SRR5476913_sorted.bam Fail to open /home/stu4/SRR5476914_sorted.bam /home/stu4/SRR5476915_sorted.bam read outcome totals across all BAMs USED: 0 NOT_PAIRED: 0 NOT_NH_1: 0 NOT_EXPECTED_CIGAR: 0 NOT_EXPECTED_READ_LENGTH: 0 NOT_EXPECTED_STRAND: 0 EXON_NOT_MATCHED_TO_ANNOTATION: 0 JUNCTION_NOT_MATCHED_TO_ANNOTATION: 0 CLIPPED: 0 total: 0 outcomes by BAM written to: /home/stu4/rMATS_output/tmp/2025-07-01-01:37:15_478511_read_outcomes_by_bam.txt novel: 0.000968933105469 The splicing graph and candidate read have been saved into /home/stu4/rMATS_output/tmp/2025-07-01-01:37:15_478511_*.rmats save: 0.000121116638184 Traceback (most recent call last): File "/opt/Anaconda3/envs/rmats/bin/rmats.py", line 536, in <module> main() File "/opt/Anaconda3/envs/rmats/bin/rmats.py", line 507, in main run_pipe(args) File "rmatspipeline/rmatspipeline.pyx", line 3803, in rmats.rmatspipeline.run_pipe File "rmatspipeline/rmatspipeline.pyx", line 3666, in rmats.rmatspipeline.split_sg_files_by_bam File "rmatspipeline/rmatspipeline.pyx", line 3674, in rmats.rmatspipeline.split_sg_files_by_bam ValueError: invalid literal for int() with base 10: '/home/stu4/SRR5476913_sorted.bam'
最新发布
07-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值