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


Java ByteArrayResource类代码示例

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


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

示例1: defendantResponseCopy

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
@ApiOperation("Returns a Defendant Response copy for a given claim external id")
@GetMapping(
    value = "/defendantResponseCopy/{externalId}",
    produces = MediaType.APPLICATION_PDF_VALUE
)
public ResponseEntity<ByteArrayResource> defendantResponseCopy(
    @ApiParam("Claim external id")
    @PathVariable("externalId") @NotBlank String externalId
) {
    byte[] pdfDocument = documentsService.generateDefendantResponseCopy(externalId);

    return ResponseEntity
        .ok()
        .contentLength(pdfDocument.length)
        .body(new ByteArrayResource(pdfDocument));
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:17,代码来源:DocumentsController.java

示例2: claimIssueReceipt

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
@ApiOperation("Returns a Claim Issue receipt for a given claim external id")
@GetMapping(
    value = "/claimIssueReceipt/{externalId}",
    produces = MediaType.APPLICATION_PDF_VALUE
)
public ResponseEntity<ByteArrayResource> claimIssueReceipt(
    @ApiParam("Claim external id")
    @PathVariable("externalId") @NotBlank String externalId
) {
    byte[] pdfDocument = documentsService.generateClaimIssueReceipt(externalId);

    return ResponseEntity
        .ok()
        .contentLength(pdfDocument.length)
        .body(new ByteArrayResource(pdfDocument));
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:17,代码来源:DocumentsController.java

示例3: sendEmail

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
@Override
public void sendEmail(@NonNull final Mail _mail,
                      @NonNull final String _body,
                      @Nullable final String _attachmentFilename,
                      @Nullable final byte[] _pdfAttachment) {
    try {
        // Prepare message using a Spring helper
        final MimeMessage mimeMessage = mailSender.createMimeMessage();
        final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, (_pdfAttachment != null), StandardCharsets.UTF_8.name());
        message.setSubject("Tifoon Scan Report");
        message.setFrom(_mail.getSender());
        message.setTo(_mail.getRecipient());

        message.setText(_body, true);

        if (_attachmentFilename != null && _pdfAttachment != null) {
            message.addAttachment(_attachmentFilename, new ByteArrayResource(_pdfAttachment));
        }

        // Send mail
        mailSender.send(mimeMessage);
    } catch (MessagingException _e) {
        log.error("Failed to send e-mail", _e);
    }
}
 
开发者ID:jonfryd,项目名称:tifoon,代码行数:26,代码来源:ReportEmailSenderServiceImpl.java

示例4: generateFromHtml

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
@APIDeprecated(
    name = "/api/v1/pdf-generator/html",
    docLink = "https://github.com/hmcts/cmc-pdf-service#standard-api",
    expiryDate = "2018-02-08",
    note = "Please use `/pdfs` instead.")
@ApiOperation("Returns a PDF file generated from provided HTML/Twig template and placeholder values")
@PostMapping(
    value = "/html",
    consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
    produces = MediaType.APPLICATION_PDF_VALUE
)
public ResponseEntity<ByteArrayResource> generateFromHtml(
    @ApiParam("A HTML/Twig file. CSS should be embedded, images should be embedded using Data URI scheme")
    @RequestParam("template") MultipartFile template,
    @ApiParam("A JSON structure with values for placeholders used in template file")
    @RequestParam("placeholderValues") String placeholderValues
) {
    log.debug("Received a PDF generation request");
    byte[] pdfDocument = htmlToPdf.convert(asBytes(template), asMap(placeholderValues));
    log.debug("PDF generated");
    return ResponseEntity
        .ok()
        .contentLength(pdfDocument.length)
        .body(new ByteArrayResource(pdfDocument));
}
 
开发者ID:hmcts,项目名称:cmc-pdf-service,代码行数:26,代码来源:PDFGenerationEndpoint.java

示例5: legalSealedClaim

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
@ApiOperation("Returns a sealed claim copy for a given claim external id")
@GetMapping(
    value = "/legalSealedClaim/{externalId}",
    produces = MediaType.APPLICATION_PDF_VALUE
)
public ResponseEntity<ByteArrayResource> legalSealedClaim(
    @ApiParam("Claim external id")
    @PathVariable("externalId") @NotBlank String externalId,
    @RequestHeader(HttpHeaders.AUTHORIZATION) String authorisation
) {
    byte[] pdfDocument = documentsService.getLegalSealedClaim(externalId, authorisation);

    return ResponseEntity
        .ok()
        .contentLength(pdfDocument.length)
        .body(new ByteArrayResource(pdfDocument));
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:18,代码来源:DocumentsController.java

示例6: countyCourtJudgement

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
@ApiOperation("Returns a County Court Judgement for a given claim external id")
@GetMapping(
    value = "/ccj/{externalId}",
    produces = MediaType.APPLICATION_PDF_VALUE
)
public ResponseEntity<ByteArrayResource> countyCourtJudgement(
    @ApiParam("Claim external id")
    @PathVariable("externalId") @NotBlank String externalId
) {
    byte[] pdfDocument = documentsService.generateCountyCourtJudgement(externalId);

    return ResponseEntity
        .ok()
        .contentLength(pdfDocument.length)
        .body(new ByteArrayResource(pdfDocument));
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:17,代码来源:DocumentsController.java

示例7: settlementAgreement

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
@ApiOperation("Returns a settlement agreement for a given claim external id")
@GetMapping(
    value = "/settlementAgreement/{externalId}",
    produces = MediaType.APPLICATION_PDF_VALUE
)
public ResponseEntity<ByteArrayResource> settlementAgreement(
    @ApiParam("Claim external id")
    @PathVariable("externalId") @NotBlank String externalId
) {
    byte[] pdfDocument = documentsService.generateSettlementAgreement(externalId);

    return ResponseEntity
        .ok()
        .contentLength(pdfDocument.length)
        .body(new ByteArrayResource(pdfDocument));
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:17,代码来源:DocumentsController.java

示例8: defendantResponseReceipt

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
@ApiOperation("Returns a Defendant Response receipt for a given claim external id")
@GetMapping(
    value = "/defendantResponseReceipt/{externalId}",
    produces = MediaType.APPLICATION_PDF_VALUE
)
public ResponseEntity<ByteArrayResource> defendantResponseReceipt(
    @ApiParam("Claim external id")
    @PathVariable("externalId") @NotBlank String externalId
) {
    byte[] pdfDocument = documentsService.generateDefendantResponseReceipt(externalId);

    return ResponseEntity
        .ok()
        .contentLength(pdfDocument.length)
        .body(new ByteArrayResource(pdfDocument));
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:17,代码来源:DocumentsController.java

示例9: fetchX509CRLFromAttribute

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
/**
 * Gets x509 cRL from attribute. Retrieves the binary attribute value,
 * decodes it to base64, and fetches it as a byte-array resource.
 *
 * @param aval the attribute, which may be null if it's not found
 * @return the x 509 cRL from attribute
 * @throws Exception if attribute not found or could could not be decoded.
 */
protected X509CRL fetchX509CRLFromAttribute(final LdapAttribute aval) throws Exception {
    if (aval != null) {
        final byte[] val = aval.getBinaryValue();
        if (val == null || val.length == 0) {
            throw new CertificateException("Empty attribute. Can not download CRL from ldap");
        }
        final byte[] decoded64 = CompressionUtils.decodeBase64ToByteArray(val);
        if (decoded64 == null) {
            throw new CertificateException("Could not decode the attribute value to base64");
        }
        logger.debug("Retrieved CRL from ldap as byte array decoded in base64. Fetching...");
        return super.fetch(new ByteArrayResource(decoded64));
    }
    throw new CertificateException("Attribute not found. Can not retrieve CRL");
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:24,代码来源:LdaptiveResourceCRLFetcher.java

示例10: fetchX509CRLFromAttribute

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
/**
 * Gets x509 cRL from attribute. Retrieves the binary attribute value,
 * decodes it to base64, and fetches it as a byte-array resource.
 *
 * @param aval the attribute, which may be null if it's not found
 * @return the x 509 cRL from attribute
 * @throws IOException          the exception thrown if resources cant be fetched
 * @throws CRLException         the exception thrown if resources cant be fetched
 * @throws CertificateException if connection to ldap fails, or attribute to get the revocation list is unavailable
 */
protected X509CRL fetchX509CRLFromAttribute(final LdapAttribute aval) throws CertificateException, IOException, CRLException {
    if (aval != null && aval.isBinary()) {
        final byte[] val = aval.getBinaryValue();
        if (val == null || val.length == 0) {
            throw new CertificateException("Empty attribute. Can not download CRL from ldap");
        }
        final byte[] decoded64 = EncodingUtils.decodeBase64(val);
        if (decoded64 == null) {
            throw new CertificateException("Could not decode the attribute value to base64");
        }
        LOGGER.debug("Retrieved CRL from ldap as byte array decoded in base64. Fetching...");
        return super.fetch(new ByteArrayResource(decoded64));
    }
    throw new CertificateException("Attribute not found. Can not retrieve CRL");
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:26,代码来源:LdaptiveResourceCRLFetcher.java

示例11: test

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
@Test
public void test() {
	
	InputStreamSource source = new ByteArrayResource(this.expectedText.getBytes(StandardCharsets.UTF_8));
	assertThat(source).isNotNull();
	PhotoLocationExtraPhotosKeywordCSVParser parser = new PhotoLocationExtraPhotosKeywordCSVParser(source);
	
	assertThat(parser).isNotNull();
	Map<String, List<String>> parsedMap = null;
	try {
		parsedMap = parser.parse();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		fail("exception on parse: "+ e.getMessage());
	}
	assertThat(parsedMap).isNotNull();
	
	assertThat(parsedMap.size()).isEqualTo(3);
	assertThat(parsedMap.keySet()).contains("DSC00305.txt","DSC00498.txt","DSC00520.txt");
	List<String> photo1 = parsedMap.get("DSC00305.txt");
	assertThat(photo1.size()).isEqualTo(2);
	assertThat(photo1.get(0)).isNotNull();
	assertThat(photo1.get(0)).isEqualTo(bosque.getName());
	assertThat(photo1.get(1)).isNotNull();
	assertThat(photo1.get(1)).isEqualTo(montanias.getName());
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:27,代码来源:PhotoLocationExtraPhotosKeywordCSVParserTest.java

示例12: testTagPoolParser

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
@Test
public void testTagPoolParser () throws BuenOjoCSVParserException {

	TagPoolCSVParser parser = new TagPoolCSVParser(new ByteArrayResource(csvString.getBytes(StandardCharsets.UTF_8)));
	Course course = new Course();
	course.setId(new Long(1000));
	try {
		List<Tag> tags = parser.parse(course);
		assertThat(tags).isNotNull().isNotEmpty();
		assertThat(tags.size()).isNotZero().isEqualTo(7);
		assertThat(tags.get(0).getNumber()).isEqualTo(1);
		assertThat(tags.get(1).getNumber()).isEqualTo(2);
		List<TagPool> tagPool = parser.parseTagPool();
		assertThat(tagPool).isNotNull().isNotEmpty();
		assertThat(tagPool.size()).isNotZero().isEqualTo(11);
		
	} catch (IOException e) {
	
		Fail.fail(e.getMessage());
	}
	
	
	
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:25,代码来源:TagPoolCSVParserTest.java

示例13: testKeywordParsing

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
@Test
public void testKeywordParsing() {
	
	String  level = "\"\",\"Niveles\",\"Paisaje\"\n\"1\",\"5:20\",\"Colinas,Llano,Veg media,Veg escasa\"";
	InputStreamSource source =new ByteArrayResource(level.getBytes(StandardCharsets.UTF_8));
	PhotoLocationLandscapeLevelsCSVParser parser = new PhotoLocationLandscapeLevelsCSVParser(source);
	
	try {
		List<String> keywords = parser.parseKeywords();
		assertThat(keywords).isNotNull();
		assertThat(keywords.size()).isEqualTo(4);
		
	} catch (IOException | BuenOjoCSVParserException e) {
		fail(e.getMessage());
		
	}
	
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:19,代码来源:PhotoLocationLandscapeLevelsCSVParserTest.java

示例14: testLandscapeLevelParsing

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
@Test
public void testLandscapeLevelParsing() {
	String  level = "\"\",\"Niveles\",\"Paisaje\"\n\"1\",\"5:20\",\"Colinas,Llano,Veg media,Veg escasa\"";
	InputStreamSource source =new ByteArrayResource(level.getBytes(StandardCharsets.UTF_8));
	PhotoLocationLandscapeLevelsCSVParser parser = new PhotoLocationLandscapeLevelsCSVParser(source);
	 try {
		Integer[] levels = parser.parseLevels();
		assertThat(levels).isNotNull();
		assertThat(levels.length).isEqualTo(2);
		assertThat(levels[0]).isNotNull().isEqualTo(5);
		assertThat(levels[1]).isNotNull().isEqualTo(20);
		
	} catch (BuenOjoCSVParserException | IOException e) {

		fail(e.getMessage());
		
	}
	 
	 
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:21,代码来源:PhotoLocationLandscapeLevelsCSVParserTest.java

示例15: cut

import org.springframework.core.io.ByteArrayResource; //导入依赖的package包/类
@GetMapping("{size}/{fileName:.+}")
public ResponseEntity<Resource> cut(@PathVariable String fileName, @PathVariable String size) throws IOException {

    try {
        Resource file = storageService.loadAsResource(fileName);
        String fileExtendName = fileName.substring(fileName.lastIndexOf(".") + 1);
        String[] wh = size.split("_");
        int w = Integer.parseInt(wh[0]);
        int h = Integer.parseInt(wh[1]);

        return ResponseEntity
                .ok()
                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+fileName+"\"")
                .body(new ByteArrayResource(ImageUtil.compress(file.getInputStream(), fileExtendName, w, h)));
    } catch (IOException e) {
        e.printStackTrace();
        return ResponseEntity
                .ok()
                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+fileName+"\"")
                .body(new ByteArrayResource(new byte[]{}));
    }
}
 
开发者ID:myliang,项目名称:fish-admin,代码行数:23,代码来源:FileUploadController.java


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