Java 类org.apache.commons.codec.binary.Base64InputStream 实例源码

项目:citizenship-appointment-server    文件:PassUpdateServiceTest.java   
private PushNotificationClient pushNotificationClient() throws IOException {
    return new PushNotificationClient(
            "passTypeIdentifier",
            IOUtils.toString(new Base64InputStream(getClass().getClassLoader().getResourceAsStream("wallet/test.p12"), true)),
            "test",
            "true") {
        @Override
        public void connect() {
        }

        @Override
        public PushNotificationResponse sendPushNotification(String pushToken) {
            return new PushNotificationResponse(true, "", false);
        }

        @Override
        public void disconnect() {
        }
    };
}
项目:ontopia    文件:OccurrenceTest.java   
public void _testBinaryReader() throws Exception {
  // read file and store in occurrence
  String file = TestFileUtils.getTestInputFile("various", "blob.gif");
  Reader ri = new InputStreamReader(new Base64InputStream(new FileInputStream(file), true), "utf-8");
  occurrence.setReader(ri, file.length(), DataTypes.TYPE_BINARY);

  assertTrue("Occurrence datatype is incorrect", Objects.equals(DataTypes.TYPE_BINARY, occurrence.getDataType()));

  // read and decode occurrence content
  Reader ro = occurrence.getReader();
  assertTrue("Reader value is null", ro != null);
  InputStream in = new Base64InputStream(new ReaderInputStream(ro, "utf-8"), false);
  try {
    OutputStream out = new FileOutputStream("/tmp/blob.gif");
    try {
      IOUtils.copy(in, out);
    } finally {
      out.close();
    }
  } finally {
    in.close();
  }
}
项目:ontopia    文件:UploadIFrame.java   
@Override
public void onSubmit() {
  FileUpload upload = uploadField.getFileUpload();         
  if (upload != null) {
    try {
      Reader input = new InputStreamReader(new Base64InputStream(upload.getInputStream(), true), "utf-8");
      FieldInstance fieldInstance = fieldValueModel.getFieldInstanceModel().getFieldInstance();
      StringWriter swriter = new StringWriter();
      IOUtils.copy(input, swriter);
      String value = swriter.toString();
      fieldInstance.addValue(value, getLifeCycleListener());
      fieldValueModel.setExistingValue(value);
      uploaded = true;
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
项目:jester    文件:EnrollmentServlet.java   
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    CertificationRequest csr = decoder.decode(new Base64InputStream(request.getInputStream()));

    try {
        response.setContentType(APPLICATION_PKCS7_MIME);
        response.addHeader("Content-Transfer-Encoding", "base64");
        X509Certificate certificate = est.enroll(csr);
        Base64OutputStream bOut = new Base64OutputStream(response.getOutputStream());
        encoder.encode(bOut, certificate);
        bOut.flush();
        bOut.close();

    } catch (IOException e) {
        response.sendError(500);
        response.getWriter().write(e.getMessage());
        response.getWriter().close();

    }

    // 202
    // Retry-After

    // 400
}
项目:xmlsec-gost    文件:TransformBase64Decode.java   
@Override
public void transform(InputStream inputStream) throws XMLStreamException {
    if (getOutputStream() != null) {
        super.transform(inputStream);
    } else {
        super.transform(new Base64InputStream(inputStream, false));
    }
}
项目:jasperreports    文件:Base64Util.java   
/**
 * Decode an input stream and write processed data to an output stream
 * @param in the input stream to be decoded
 * @param out the output stream to write the decoded data
 * @throws IOException
 */
public static void decode(InputStream in, OutputStream out) throws IOException
{
    Base64InputStream base64is = new Base64InputStream(in);

    copy(base64is, out);
}
项目:jasperreports    文件:Base64Util.java   
/**
 * Encode an input stream and write processed data to an output stream
 * @param in the input stream to be encoded
 * @param out the output stream to write the encoded data
 * @throws IOException
 */
public static void encode(InputStream in, OutputStream out) throws IOException
{
    Base64InputStream base64is = new Base64InputStream(in, true, DEFAULT_LINE_LENGTH, DEFAULT_LINE_SEPARATOR);

    copy(base64is, out);
}
项目:citizenship-appointment-server    文件:PassBuilder.java   
PKSigningInformation createSigningInformation() {
    InputStream appleWwdrcaAsStream = getClass().getClassLoader().getResourceAsStream("wallet/AppleWWDRCA.pem");
    InputStream base64EncodedPrivateKeyAndCertificatePkcs12AsStream = new ByteArrayInputStream(privateKeyP12Base64.getBytes(StandardCharsets.UTF_8));
    Base64InputStream privateKeyAndCertificatePkcs12AsStream = new Base64InputStream(base64EncodedPrivateKeyAndCertificatePkcs12AsStream);
    try {
        return new PKSigningInformationUtil().loadSigningInformationFromPKCS12AndIntermediateCertificate(privateKeyAndCertificatePkcs12AsStream, privateKeyPassPhrase, appleWwdrcaAsStream);
    } catch (IOException | NoSuchAlgorithmException | CertificateException | KeyStoreException | NoSuchProviderException | UnrecoverableKeyException e) {
        throw new RuntimeException("Problem creating pass signing information", e);
    }
}
项目:citizenship-appointment-server    文件:PushNotificationClient.java   
@Autowired
public PushNotificationClient(@Value("${wallet.pass.type.identifier}") String passTypeIdentifier,
                              @Value("${wallet.private.key.p12.base64}") String privateKeyP12Base64,
                              @Value("${wallet.private.key.passphrase}") String privateKeyPassPhrase,
                              @Value("${wallet.push.notifications.enabled:true}") String pushNotificationsEnabled) {
    this.passTypeIdentifier = passTypeIdentifier;
    this.pushNotificationsEnabled = !"false".equalsIgnoreCase(pushNotificationsEnabled);
    ByteArrayInputStream base64EncodedPrivateKeyAndCertificatePkcs12AsStream = new ByteArrayInputStream(privateKeyP12Base64.getBytes(StandardCharsets.UTF_8));
    Base64InputStream privateKeyAndCertificatePkcs12AsStream = new Base64InputStream(base64EncodedPrivateKeyAndCertificatePkcs12AsStream);
    try {
        this.client = new ApnsClient<>(privateKeyAndCertificatePkcs12AsStream, privateKeyPassPhrase);
    } catch (SSLException e) {
        throw new RuntimeException("Problem creating APNs client", e);
    }
}
项目:FinanceAnalytics    文件:Compressor.java   
static void decompressStream(InputStream inputStream, OutputStream outputStream) throws IOException {
  @SuppressWarnings("resource")
  InputStream iStream = new GZIPInputStream(new Base64InputStream(new BufferedInputStream(inputStream), false, -1, null));
  OutputStream oStream = new BufferedOutputStream(outputStream);
  byte[] buffer = new byte[2048];
  int bytesRead;
  while ((bytesRead = iStream.read(buffer)) != -1) {
    oStream.write(buffer, 0, bytesRead);
  }
  oStream.flush();
}
项目:adf-selenium    文件:FileOutputType.java   
@Override
public File convertFromBase64Png(String base64Png) {
    try {
        IOUtils.copy(new Base64InputStream(IOUtils.toInputStream(base64Png)), new FileOutputStream(file));
    } catch (IOException e) {
        throw new WebDriverException(e);
    }
    return file;
}
项目:extract    文件:DataURIEncodingInputStream.java   
public DataURIEncodingInputStream(final InputStream in, final MediaType type) {

        // Only text documents should be URL-encoded. It doesn't matter if the encoding is supported or not because
        // the URL-encoder works on raw bytes. Everything else must be base-64-encoded.
        if (type.getType().equals("text")) {
            this.prepend = ("data:" + type + ",").getBytes(StandardCharsets.US_ASCII);
            this.encoder = new URLEncodingInputStream(in);
        } else {
            this.prepend = ("data:" + type + ";base64,").getBytes(StandardCharsets.US_ASCII);
            this.encoder = new Base64InputStream(in, true, -1, null);
        }
    }
项目:praisenter    文件:ImageUtilities.java   
/**
 * Converts the given base 64 string into a BufferedImage object.
 * @param string the base 64 string
 * @return BufferedImage
 * @throws IOException if an exception occurs reading the image data
 */
public static final BufferedImage getBase64StringImage(String string) throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(string.getBytes());
    BufferedInputStream bis = new BufferedInputStream(bais);
    Base64InputStream b64is = new Base64InputStream(bis);
    return ImageIO.read(b64is);
}
项目:ontopia    文件:OccurrenceWebResource.java   
@Override
public InputStream getInputStream() throws ResourceStreamNotFoundException {
  try {
    return new Base64InputStream(new ReaderInputStream(reader, "utf-8"), false);
  } catch (UnsupportedEncodingException e) {
    throw new OntopiaRuntimeException(e);
  }
}
项目:jester    文件:EstClient.java   
public X509Certificate[] obtainCaCertificates() throws IOException {
    HttpGet get = new HttpGet(buildUrl(CA_CERTIFICATES_DISTRIBUTION));
    HttpResponse response = httpClient.execute(get);

    int statusCode = response.getStatusLine().getStatusCode();
    checkStatusCode(statusCode, 200);
    checkContentType(response);
    checkContentTransferEncoding(response);

    HttpEntity entity = response.getEntity();
    X509Certificate[] certs = certDecoder.decode(new Base64InputStream(entity.getContent()));

    return certs;
}
项目:jester    文件:EstClient.java   
private EnrollmentResponse enroll(CertificationRequest csr, String command) throws IOException {
    HttpPost post = new HttpPost(buildUrl(command));
    post.addHeader("Content-Type", "application/pkcs10");
    post.addHeader("Content-Transfer-Encoding", "base64");
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    Base64OutputStream base64Out = new Base64OutputStream(bOut);
    csrEncoder.encode(base64Out, csr);
    base64Out.flush();
    base64Out.close();
    post.setEntity(new ByteArrayEntity(bOut.toByteArray()));
    HttpResponse response = httpClient.execute(post);

    int statusCode = response.getStatusLine().getStatusCode();
    checkStatusCode(statusCode, 200, 202);
    if (statusCode == 200) {
        checkContentType(response);
        checkContentTransferEncoding(response);

        HttpEntity entity = response.getEntity();
        X509Certificate[] certs = certDecoder.decode(new Base64InputStream(entity.getContent()));

        return new EnrollmentResponse(certs[0]);
    } else {
        String retryAfter = response.getFirstHeader("Retry-After").getValue();
        return new EnrollmentResponse(RetryAfterParser.parse(retryAfter));
    }
}
项目:iaf    文件:JdbcUtil.java   
public static void streamBlob(Blob blob, String column, String charset, boolean blobIsCompressed, String blobBase64Direction, Object target, boolean close) throws JdbcException, SQLException, IOException {
    if (target==null) {
        throw new JdbcException("cannot stream Blob to null object");
    }
    OutputStream outputStream=StreamUtil.getOutputStream(target);
    if (outputStream!=null) {
        InputStream inputStream = JdbcUtil.getBlobInputStream(blob, column, blobIsCompressed);
        if ("decode".equalsIgnoreCase(blobBase64Direction)){
            Base64InputStream base64DecodedStream = new Base64InputStream (inputStream);
            StreamUtil.copyStream(base64DecodedStream, outputStream, 50000);                    
        }
        else if ("encode".equalsIgnoreCase(blobBase64Direction)){
            Base64InputStream base64EncodedStream = new Base64InputStream (inputStream, true);
            StreamUtil.copyStream(base64EncodedStream, outputStream, 50000);                                    
        }
        else {  
            StreamUtil.copyStream(inputStream, outputStream, 50000);
        }

        if (close) {
            outputStream.close();
        }
        return;
    }
    Writer writer = StreamUtil.getWriter(target);
    if (writer !=null) {
        Reader reader = JdbcUtil.getBlobReader(blob, column, charset, blobIsCompressed);
        StreamUtil.copyReaderToWriter(reader, writer, 50000, false, false);
        if (close) {
            writer.close();
        }
        return;
    }
    throw new IOException("cannot stream Blob to ["+target.getClass().getName()+"]");
}
项目:cobbzilla-utils    文件:Base64ImageInsertion.java   
@Override public File getImageFile() throws IOException {
    if (empty(getImage())) return null;
    final File temp = temp("."+getFormat());
    final Base64InputStream stream = new Base64InputStream(new ByteArrayInputStream(image.getBytes()));
    FileUtil.toFile(temp, stream);
    return temp;
}
项目:ILIASDownloader2    文件:FileSync.java   
@Override
public InputStream doSomething(InputStream inputStream) {
    return new Base64InputStream(inputStream);
}
项目:ILIASDownloader2    文件:SyncService.java   
@Override
public InputStream doSomething(InputStream inputStream) {
    return new Base64InputStream(inputStream);
}
项目:Camel    文件:Base64DataFormat.java   
@Override
public Object unmarshal(Exchange exchange, InputStream input) throws Exception {
    return new Base64InputStream(input, false, lineLength, lineSeparator);
}
项目:openprodoc    文件:PDDocs.java   
private void setStreamB64(InputStream B64InputStream)
{
FileStream=new Base64InputStream(B64InputStream,false);
}
项目:EmailModuleWithTemplates    文件:Sender.java   
@Override
public InputStream getInputStream() throws IOException {
    InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
    return new Base64InputStream(stream);
}
项目:backups    文件:Base64EncodingCodec.java   
@Override
public InputStream input(InputStream in) throws IOException {
    return new Base64InputStream(in);
}
项目:incubator-gobblin    文件:Base64Codec.java   
private InputStream decodeInputStreamWithApache(InputStream origStream) {
  return new Base64InputStream(origStream);
}
项目:spring-restlet    文件:ServletUtil.java   
/**
 * Converts the given {@code HttpResponse} into JSON form, with at least
 * one field, dataUri, containing a Data URI that can be inlined into an HTML page.
 * Any metadata on the given {@code HttpResponse} is also added as fields.
 * 
 * @param response Input HttpResponse to convert to JSON.
 * @return JSON-containing HttpResponse.
 * @throws IOException If there are problems reading from {@code response}.
 */
public static HttpResponse convertToJsonResponse(HttpResponse response) throws IOException {
    // Pull out charset, if present. If not, this operation simply returns contentType.
    String contentType = response.getHeader("Content-Type");
    if (contentType == null) {
        contentType = "";
    } else if (contentType.contains(";")) {
        contentType = StringUtils.split(contentType, ';')[0].trim();
    }
    // First and most importantly, emit dataUri.
    // Do so in streaming fashion, to avoid needless buffering.
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(os);
    pw.write("{\n  ");
    pw.write(DATA_URI_KEY);
    pw.write(":'data:");
    pw.write(contentType);
    pw.write(";base64;charset=");
    pw.write(response.getEncoding());
    pw.write(",");
    pw.flush();

    // Stream out the base64-encoded data.
    // Ctor args indicate to encode w/o line breaks.
    Base64InputStream b64input = new Base64InputStream(response.getResponse(), true, 0, null);
    byte[] buf = new byte[1024];
    int read = -1;
    try {
        while ((read = b64input.read(buf, 0, 1024)) > 0) {
            os.write(buf, 0, read);
        }
    } finally {
        IOUtils.closeQuietly(b64input);
    }

    // Complete the JSON object.
    pw.write("',\n  ");
    boolean first = true;
    for (Map.Entry<String, String> metaEntry : response.getMetadata().entrySet()) {
        if (DATA_URI_KEY.equals(metaEntry.getKey()))
            continue;
        if (!first) {
            pw.write(",\n  ");
        }
        first = false;
        pw.write("'");
        pw.write(StringEscapeUtils.escapeJavaScript(metaEntry.getKey()).replace("'", "\'"));
        pw.write("':'");
        pw.write(StringEscapeUtils.escapeJavaScript(metaEntry.getValue()).replace("'", "\'"));
        pw.write("'");
    }
    pw.write("\n}");
    pw.flush();

    return new HttpResponseBuilder().setHeader("Content-Type", "application/json").setResponseNoCopy(os.toByteArray()).create();
}
项目:jester    文件:BouncyCastleSignedDataDecoderTest.java   
@Test
public void testExampleBody() throws Exception {
    X509Certificate[] certs = decoder.decode(new Base64InputStream(getClass().getResourceAsStream("/cacerts.msg")));

    assertEquals("Expected four certificates", 4, certs.length);
}
项目:temporary-groupdocs-java-sdk    文件:ApiInvoker.java   
public static String readAsDataURL(InputStream is, String contentType) throws IOException  {
String base64file = IOUtils.toString(new Base64InputStream(is, true, 0, null));
return "data:" + contentType + ";base64,"  + base64file;
 }
项目:groupdocs-java    文件:MimeUtils.java   
public static String readAsDataURL(InputStream is, String contentType)
        throws IOException {
    String base64file = IOUtils.toString(new Base64InputStream(is, true, 0,
            null));
    return "data:" + contentType + ";base64," + base64file;
}
项目:savot    文件:DataBinaryReader.java   
/**
 * <p>Gets a stream which decodes data coming from the given input stream.</p>
 * 
 * <p>NOTE: Accepted encoding algorithms are: <code>base64</code> or <code>gzip</code>.</p>
 * 
 * @param encodedStream     Input stream on encoded data.
 * @param encoding          Name of the encoding algorithm (<code>base64</code> or <code>gzip</code>).
 * 
 * @return              An input stream which decodes the encoded data read from the given input stream.
 * 
 * @throws IOException      If there is an error while building the input stream.
 * 
 * @see Base64InputStream
 * @see GZIPInputStream
 */
private InputStream getDecodedStream(final InputStream encodedStream, final String encoding) throws IOException {
    if (encoding == null || encoding.isEmpty()) {
        return encodedStream;
    } else if (encoding.equalsIgnoreCase("base64")) {
        return new Base64InputStream(encodedStream);
    } else if (encoding.equalsIgnoreCase("gzip")) {
        return new GZIPInputStream(encodedStream);
    } else {
        throw new BinaryInterpreterException("Unknown encoding \"" + encoding + "\" ! It must be either \"base64\" or \"gzip\" !");
    }
}