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