包含jbig.java的词条
本篇文章给大家谈谈jbig.java,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、如何使用java从excel表提取内容
- 2、提问 了很多次的问题了。关于Java程序的,麻烦高手看一下
- 3、rsa算法中p,q,n,e,d一般大小都为多少啊?
- 4、编写java循环程序,有100匹马驮100担货,大马驮3担,中马驮2担,两匹小马驮一担,问有大、中
- 5、如何解压缩jbig字节数组
如何使用java从excel表提取内容
以下是使用java从excel表提取内容的程序 -
import java.io.File;import java.io.FileInputStream;import org.apache.tika.metadata.Metadata;import org.apache.tika.parser.ParseContext;import org.apache.tika.parser.microsoft.ooxml.OOXMLParser;import org.apache.tika.sax.BodyContentHandler;public class ExtractContentFromExcel {
public static void main(String args[]) throws Exception {
// detecting the file type
BodyContentHandler handler = new BodyContentHandler();
Metadata metadata = new Metadata();
FileInputStream inputstream = new FileInputStream(new File("excelExample.xlsx"));
ParseContext pcontext = new ParseContext();
// OOXml parser
OOXMLParser msofficeparser = new OOXMLParser();
msofficeparser.parse(inputstream, handler, metadata, pcontext);
System.out.println("Contents of the document:" + handler.toString());
System.out.println("Metadata of the document:");
String[] metadataNames = metadata.names();
for (String name : metadataNames) {
System.out.println(name + ": " + metadata.get(name));
}
}}Java
原ODF文件:excelExample.xlsx 的内容如下 -
执行上面示例代码,得到以下结果 -
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/F:/worksp/javaexamples/libs/tika_libs/tika-app-1.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/F:/worksp/javaexamples/libs/tika_libs/tika-server-1.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
九月 27, 2017 5:15:47 上午 org.apache.tika.config.InitializableProblemHandler$3 handleInitializableProblem
警告: JBIG2ImageReader not loaded. jbig2 files will be ignored
See
for optional dependencies.
TIFFImageWriter not loaded. tiff files will not be processed
See
for optional dependencies.
J2KImageReader not loaded. JPEG2000 files will not be processed.
See
for optional dependencies.
九月 27, 2017 5:15:47 上午 org.apache.tika.config.InitializableProblemHandler$3 handleInitializableProblem
警告: org.xerial's sqlite-jdbc is not loaded.
Please provide the jar on your classpath to parse sqlite files.
See tika-parsers/pom.xml for the correct version.
Contents of the document:Sheet1
编号 姓名 年龄 工作
1001 王传大 22 Java软件开发
1002 李小双 29 项目经理
1020 张在传 28 人事经理
Sheet2
Sheet3
Metadata of the document:
date: 2017-09-27T09:15:38Z
meta:creation-date: 2017-09-27T09:13:50Z
extended-properties:Application: Microsoft Excel
Creation-Date: 2017-09-27T09:13:50Z
dcterms:created: 2017-09-27T09:13:50Z
Last-Modified: 2017-09-27T09:15:38Z
dcterms:modified: 2017-09-27T09:15:38Z
Last-Save-Date: 2017-09-27T09:15:38Z
protected: false
meta:save-date: 2017-09-27T09:15:38Z
Application-Name: Microsoft Excel
modified: 2017-09-27T09:15:38Z
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
custom:KSOProductBuildVer: 2052-10.1.0.6489Shell
易百教程移动端:请扫描本页面底部(右侧)二维码并关注微信公众号,回复:"教程" 选择相关教程阅读或直接访问: 。
提问 了很多次的问题了。关于Java程序的,麻烦高手看一下
试了十分钟终于好了,你看看
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class lianxi3 extends JFrame implements ActionListener{
JPanel jPanel,jPanel1;
JLabel jLabel;
Image image;
ImageIcon imageIcon;
JButton jButton;
float www=1;
float hhh=1;
public lianxi3() {
super("图片");
jPanel1=new JPanel();
jButton = new JButton("变大");
jButton.addActionListener(this);
image = Toolkit.getDefaultToolkit().getImage("src/1.jpg");
jLabel = new JLabel();
jPanel1.add(jButton);
imageIcon = new ImageIcon(image);
jLabel.setIcon(imageIcon);
this.add(jLabel, BorderLayout.NORTH);
this.add(jPanel1, BorderLayout.SOUTH);
this.setVisible(true);
this.setSize(600, 600);
}
public static void main(String[] args) {
new lianxi3();
}
public void big(){
int width=imageIcon.getIconWidth();
int height=imageIcon.getIconWidth();
double bigger=1.25;
www=(float)(width*bigger);
hhh=(float)(height*bigger);
System.out.println(www+""+hhh);
Math.pow(www,hhh);
image = image.getScaledInstance((int)www, (int)hhh, Image.SCALE_DEFAULT);
imageIcon = new ImageIcon(image);
//jLabel.setSize((int)www, (int)hhh);
jLabel.setIcon(imageIcon);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jButton){
big();
}
}
}
rsa算法中p,q,n,e,d一般大小都为多少啊?
这个不好说,什么情况都可能不是吗。
RSA是目前最有影响力的公钥加密算法,该算法基于一个十分简单的数论事实:将两个大素数相乘十分容易,但那时想要对其乘积进行因式分解却极其困难,因此可以将乘积公开作为加密密钥,即公钥,而两个大素数组合成私钥。公钥是可发布的供任何人使用,私钥则为自己所有,供解密之用。
解密者拥有私钥,并且将由私钥计算生成的公钥发布给加密者。加密都使用公钥进行加密,并将密文发送到解密者,解密者用私钥解密将密文解码为明文。
以甲要把信息发给乙为例,首先确定角色:甲为加密者,乙为解密者。首先由乙随机确定一个KEY,称之为密匙,将这个KEY始终保存在机器B中而不发出来;然后,由这个 KEY计算出另一个KEY,称之为公匙。这个公钥的特性是几乎不可能通过它自身计算出生成它的私钥。接下来通过网络把这个公钥传给甲,甲收到公钥后,利用公钥对信息加密,并把密文通过网络发送到乙,最后乙利用已知的私钥,就对密文进行解码了。以上就是RSA算法的工作流程。
算法实现过程为:
1. 随意选择两个大的质数p和q,p不等于q,计算N=pq。
2. 根据欧拉函数,不大于N且与N互质的整数个数为(p-1)(q-1)。
3. 选择一个整数e与(p-1)(q-1)互质,并且e小于(p-1)(q-1)。
4. 用以下这个公式计算d:d× e ≡ 1 (mod (p-1)(q-1))。
5. 将p和q的记录销毁。
以上内容中,(N,e)是公钥,(N,d)是私钥。
下面讲解RSA算法的应用。
RSA的公钥和私钥是由KeyPairGenerator生成的,获取KeyPairGenerator的实例后还需要设置其密钥位数。设置密钥位数越高,加密过程越安全,一般使用1024位。如下代码:
[代码]java代码:
1KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(RSA);
2// 密钥位数
3keyPairGen.initialize(1024);
公钥和私钥可以通过KeyPairGenerator执行generateKeyPair()后生成密钥对KeyPair,通过KeyPair.getPublic()和KeyPair.getPrivate()来获取。如下代码:
[代码]java代码:
1// 动态生成密钥对,这是当前最耗时的操作,一般要2s以上。
2KeyPair keyPair = keyPairGen.generateKeyPair();
3// 公钥
4PublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
5// 私钥
6PrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
7byte[] publicKeyData = publicKey.getEncoded();
8byte[] privateKeyData = publicKey.getEncoded();
公钥和私钥都有它们自己独特的比特编码,可以通过getEncoded()方法获取,返回类型为byte[]。通过byte[]可以再度将公钥或私钥还原出来。具体代码如下:
[代码]java代码:
01// 通过公钥byte[]将公钥还原,适用于RSA算法
02public static PublicKey getPublicKey(byte[] keyBytes) throws
03NoSuchAlgorithmException,InvalidKeySpecException {
04 X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
05 KeyFactory keyFactory = KeyFactory.getInstance("RSA");
06 PublicKey publicKey = keyFactory.generatePublic(keySpec);
07 return publicKey;
08}
09// 通过私钥byte[]将公钥还原,适用于RSA算法
10public static PrivateKey getPrivateKey(byte[] keyBytes) throws
11NoSuchAlgorithmException,InvalidKeySpecException {
12 PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
13 KeyFactory keyFactory = KeyFactory.getInstance("RSA");
14 PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
15 return privateKey;
16}
在上文讲到的RSA算法实现过程中提到(N,e)是公钥,(N,d)是私钥。既然已经获取到了PublicKey和PrivateKey了,那如何取到N、e、d这三个值呢。要取到这三个值,首先要将PublicKey和PrivateKey强制转换成RSAPublicKey和RSAPrivateKey。共同的N值可以通过getModulus()获取。执行RSAPublicKey.getPublicExponent()可以获取到公钥中的e值,执行RSAPrivateKey.getPrivateExponent()可以获取私钥中的d值。这三者返回类型都是BigInteger。代码如下:
[代码]java代码:
01// 打印公钥信息
02public static void printPublicKeyInfo(PublicKey key){
03RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;
04Log.d(MainActivity.TAG, "RSAPublicKey:");
05Log.d(MainActivity.TAG, "Modulus.length=" +
06rsaPublicKey.getModulus().bitLength());
07Log.d(MainActivity.TAG, "Modulus=" +
08rsaPublicKey.getModulus().toString());
09Log.d(MainActivity.TAG, "PublicExponent.length=" +
10rsaPublicKey.getPublicExponent().bitLength());
11Log.d(MainActivity.TAG, "PublicExponent=" +
12rsaPublicKey.getPublicExponent().toString());
13}
14
15// 打印私钥信息
16public static void printPublicKeyInfo(PrivateKey key){
17RSAPrivateKey rsaPublicKey = (RSAPrivateKey) privateKey;
18Log.d(MainActivity.TAG, "RSAPrivateKey:");
19Log.d(MainActivity.TAG, "Modulus.length=" +
20rsaPrivateKey.getModulus().bitLength());
21Log.d(MainActivity.TAG, "Modulus=" +
22rsaPrivateKey.getModulus().toString());
23Log.d(MainActivity.TAG, "PublicExponent.length=" +
24rsaPrivateKey.getPrivateExponent().bitLength());
25Log.d(MainActivity.TAG, "PublicExponent=" +
26rsaPrivateKey.getPrivateExponent().toString());
27}
由于程序中动态生成KeyPair对明文加密后生成的密文是不可测的,所以在实际开发中通常在生成一个KeyPair后将公钥和私钥的N、e、d这三个特征值记录下来,在真实的开发中使用这三个特征值再去将PublicKey和PrivateKey还原出来。还原方法如下:
[代码]java代码:
01// 使用N、e值还原公钥
02public static PublicKey getPublicKey(String modulus, String
03publicExponent)
04 throws NoSuchAlgorithmException, InvalidKeySpecException {
05 BigInteger bigIntModulus = new BigInteger(modulus);
06 BigInteger bigIntPrivateExponent = new BigInteger(publicExponent);
07 RSAPublicKeySpec keySpec = new RSAPublicKeySpec(bigIntModulus,
08bigIntPrivateExponent);
09 KeyFactory keyFactory = KeyFactory.getInstance("RSA");
10 PublicKey publicKey = keyFactory.generatePublic(keySpec);
11 return publicKey;
12}
13
14// 使用N、d值还原公钥
15public static PrivateKey getPrivateKey(String modulus, String
16privateExponent)
17 throws NoSuchAlgorithmException, InvalidKeySpecException {
18 BigInteger bigIntModulus = new BigInteger(modulus);
19 BigInteger bigIntPrivateExponent = new BigInteger(privateExponent);
20 RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(bigIntModulus,
21 bigIntPrivateExponent);
22 KeyFactory keyFactory = KeyFactory.getInstance("RSA");
23 PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
24 return privateKey;
25}
公钥和私钥都具备后,就可以使用加解密的工具类javax.crypto.Cipher对明文和密文进行处理了。与所有的引擎类一样,可以通过调用Cipher类中的getInstance(String transformation)静态工厂方法得到Cipher对象。该方法中的参数描述了由指定输入产生输出所进行的操作或操作集合,可以是下列两种形式之一:“algorithm/mode/padding”或“algorithm”。例如下面的例子就是有效的transformation形式:"DES/CBC/PKCS5Padding"或"DES"。如果没有指定模式或填充方式,就使用特定提供者指定的默认模式或默认填充方式。
Cipher的加密和解密方式所调用的方法和过程都一样,只是传参不同的区别。
编写java循环程序,有100匹马驮100担货,大马驮3担,中马驮2担,两匹小马驮一担,问有大、中
设大、中、小马数量分别为x、y、z,那么:
3x+2y+z/2=100
x+y+z=100
简单置换下,可以得到5x+3y=100,马数不可能出现负数,也不为0,所以x=19(19=(100-3)/5)
int x=1,y=0,z=0,tmp=0;// 预定义几个变量。如果不是为了代码易读,tmp可省略
for (; x 20; x++) {
tmp = 100 - 5 * x;
y = tmp / 3;
z = 100 - x - y;
if (z % 2 != 0) continue;// 小马必须是两匹在一起,所以z需是偶数
if (6 * x + 4 * y + z != 200) continue;// 检查是否满足第一公式
System.out.printf("[x,y,z]=%02d,%02d,%02d;6x+4y+2z=%d;x+y+z=%d\r\n"//
, x, y, z, (6 * x + 4 * y + z), (x + y + z));
}
如何解压缩jbig字节数组
是打印机的压缩格式
JBIG (Joint Bi-level Image Experts Group),是由lossless image compession,的基础上特用于传真机的一种压缩技术。数据压缩的演绎法众多,其中使用于图像压缩的演绎法可粗分为两类,第一类就是lossless image compession,是一种压缩再解压缩后不会产生任何误差的演绎法。第二类则为lossy compression是一种压缩再解压缩后产生误差的演绎法。其中JBIG脱身于第一类lossless image compession,而JPEG(Joint Picture Expert Group)则是由第二类lossy compression发展而来的。这里需要说明的是,MH、MR、MMR、JBIG这几种压缩系统都是针对黑白文稿的压缩系统,而JPEG则是为了适应传真彩色文稿的需求而产生的。运用lossy compression来做图像压缩不但可以获得不错的压缩比,也可以兼顾不错的品质。
关于jbig.java和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-11-22,除非注明,否则均为
原创文章,转载请注明出处。