Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何通过sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream实例获取字节数组?_Java_Spring - Fatal编程技术网

Java 如何通过sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream实例获取字节数组?

Java 如何通过sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream实例获取字节数组?,java,spring,Java,Spring,我正在使用DefaultPropertiesPersister覆盖属性。我的配置是这样的 <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/> <property na

我正在使用DefaultPropertiesPersister覆盖属性。我的配置是这样的

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    <property name="locations">
      <list>
          <value>classpath:/META-INF/properties/common.properties</value>
          <value>classpath:/META-INF/properties/${spring.profiles.active}.properties</value>
          <value>classpath:/META-INF/properties/${spring.profiles.active}.passwords</value>
          <value>classpath:/META-INF/properties/local.properties</value>
      </list>
    </property>
    <property name="propertiesPersister">
        <bean class="com.freecharge.ums.server.service.MyPropertyPersister" />
    </property>        
</bean>
现在,在启动jar之后,我得到的InputStream类型为
sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream
。当我尝试使用
IOUtils.toByteArray(is)
将其转换为
byte[]
时,我什么也得不到

当我通过
main
方法运行相同的东西时,我通过了,因为我得到的流是
java.io.BufferedInputStream
,它能够将其转换为字节数组

做了很多研究,但没能完成。提前谢谢

MyPropertyPersister
类中的加载方法实现如下:

@Override
public void load(Properties props, InputStream is) throws IOException {
    Tika tika = new Tika();
    String type = tika.detect(is);
    if (!type.equals("text/plain")) {
        try {
            byte[] cipherText = IOUtils.toByteArray(is);
            ByteBuffer cipherTextBlob = ByteBuffer.wrap(cipherText);
            logger.info("cipherTextBlob: " + cipherTextBlob);
            DecryptRequest decryptReq = new DecryptRequest().withCiphertextBlob(cipherTextBlob);
            awsCredentials = new BasicAWSCredentials(AWS_KMS_KEY, AWS_KMS_SECRET);
            amazonKMSClient = new AWSKMSClient(awsCredentials).withRegion(...some region...);
            DecryptResult decryptResult = amazonKMSClient.decrypt(decryptReq);
            String fileContents = new String(decryptResult.getPlaintext().array());

            props.load(new StringReader(fileContents));                

            logger.info("props: " + props);
            super.load(props, is);
        } catch (Exception e) {
            logger.error("e: ", e);
        }            
    } else {
        super.load(props, is);
    }
}    

我希望我的问题是清楚的,如果没有请在这里评论。我将尝试澄清更多。您能在MyPropertyPersister中显示代码吗。load(Properties props,InputStream is)感谢您的回复,我已经编辑了有问题的方法。我希望我的问题是清楚的,如果没有,请在这里评论。将尝试进一步澄清。您能在MyPropertyPersister中显示代码吗。load(Properties props,InputStream is)感谢您的回复,已经编辑了有问题的方法。
@Override
public void load(Properties props, InputStream is) throws IOException {
    Tika tika = new Tika();
    String type = tika.detect(is);
    if (!type.equals("text/plain")) {
        try {
            byte[] cipherText = IOUtils.toByteArray(is);
            ByteBuffer cipherTextBlob = ByteBuffer.wrap(cipherText);
            logger.info("cipherTextBlob: " + cipherTextBlob);
            DecryptRequest decryptReq = new DecryptRequest().withCiphertextBlob(cipherTextBlob);
            awsCredentials = new BasicAWSCredentials(AWS_KMS_KEY, AWS_KMS_SECRET);
            amazonKMSClient = new AWSKMSClient(awsCredentials).withRegion(...some region...);
            DecryptResult decryptResult = amazonKMSClient.decrypt(decryptReq);
            String fileContents = new String(decryptResult.getPlaintext().array());

            props.load(new StringReader(fileContents));                

            logger.info("props: " + props);
            super.load(props, is);
        } catch (Exception e) {
            logger.error("e: ", e);
        }            
    } else {
        super.load(props, is);
    }
}