目前我正在尝试以mime格式读取文件,其中包含一些png的二进制字符串数据.
在Windows中,读取文件为我提供了正确的二进制字符串,这意味着我只需复制字符串并将扩展名更改为png即可看到图片.
在Windows中读取文件后的示例如下:
--fh-mms-multipart-next-part-1308191573195-0-53229
Content-Type: image/png;name=app_icon.png
Content-ID: "<app_icon>"
content-location: app_icon.png
‰PNG
Run Code Online (Sandbox Code Playgroud)
等...等...
在Linux中读取文件后的示例如下:
--fh-mms-multipart-next-part-1308191573195-0-53229
Content-Type: image/png;name=app_icon.png
Content-ID: "<app_icon>"
content-location: app_icon.png
�PNG
Run Code Online (Sandbox Code Playgroud)
等...等...
我无法将Linux版本转换成图片,因为它变成了一些时髦的符号,并且有很多颠倒的"?" 和"1/2"符号.
任何人都可以告诉我发生了什么,也许可以提供解决方案?已经玩了一周以上的代码了.
我一直在询问有关为Web方法编写单元测试的问题,这些方法实际上与数据库通信并返回一些值.
比方说,我有一个名为"StudentInfoService"的Web服务.该网络服务提供API"getStudentInfo(studentid)"
这是一些示例代码段
public class StudentInfoService
{
public StudentInfo getStudentInfo(long studentId) {
//Communicates with DB and creates
// StudentInfo object with necessary information
// and returns it to the caller.
}
}
Run Code Online (Sandbox Code Playgroud)
我们如何为这个方法getStudentInfo实际编写单元测试?一般来说,我们如何为涉及与资源(数据库,文件,JNDI等)连接的方法编写单元测试?
一直在尝试使用 JAI 将 ImageOutputStream 转换为 byte[] 一段时间。任何输入表示赞赏。谢谢。
抱歉,这是代码片段,我正在处理。我不得不提前发布它。我面临的问题是,我能够从 ImageOutputStream 获取 ByteArrayOutputStream。但它总是给我零字节。但是如果我使用 FileOutputStream 而不是 ByteArrayOuputStream,我可以写入一个非零字节的文件。:
File file = new File("C:/TIFFImages/tiff-image.tiff");
FileInputStream in = new FileInputStream(file);
long filelength = file.length();
byte[] bytes = new byte[(int)filelength];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead=in.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file.getName());
}
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
RenderedImage src = JAI.create("stream", SeekableStream.wrapInputStream(bais, …Run Code Online (Sandbox Code Playgroud) 我有一个jar说test.jar有TestJar作为它的主类,一个shell脚本jar_executor.sh和一个java文件.如果我们传递1作为参数,我的test.jar将返回1,如果我们传递任何其他值,则返回2.我的shell脚本正在执行test.jar,如下所示
#!/usr/bin/ksh
java TestJar 1 -cp test.jar
return_code=$?
exit $return_code
Run Code Online (Sandbox Code Playgroud)
在java文件中,我正在创建一个进程并执行shell脚本,并使用以下代码获取其exitvalue
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(sh jar_executor.sh);
int exitVal = process.waitFor();
System.out.println(exitVal);
Run Code Online (Sandbox Code Playgroud)
这个exitVal变量应该按照我们传递的参数打印1或2,但每次打印255.如果我echo $return_code在shell脚本中使用,那么我得到正确的值.请帮助我为什么我得到255的价值exit.提前致谢!!!
我正在努力想出德州扑克的Java手历史课,并想在这里反弹一个想法.
要求是每个动作都被存储,并且有一种有效的方式来遍历每个HandHistory对象(这将代表一个单独的手牌)来匹配常见的"线",就像标准的持续下注(即翻牌前和翻牌前位置的翻牌前加注者)可能是在翻牌后进行检查,然后做出75%的赌注.)
暂时忽略每条线的定义最多是模糊的.作为第一次尝试,我正在考虑如此组织它:
public class HandHistory {
private Integer handnumber;
//in case we saw things at showdown, put them here
private HashMap<Player,String> playerHands;
private String flopCards;
private String turnCard;
private String riverCard;
private HashMap<BetRound,LinkedHashMap<Integer,ArrayList<PlayerAction>>> actions;
}
Run Code Online (Sandbox Code Playgroud)
因此,对于每个betround,我们存储一个链接的hashmap,其键是整数,它是从第一个位置开始为该betround行动的偏移量,因此翻牌前UTG为0.
我们已经按位置顺序生成了动作,因此使用链接的hashmap,这样我们可以稍后很好地迭代并跳过坐在外面的位置等.
每个arraylist将包含该位置在该betround中的行为.大多数情况下,这个数组将有一个元素,但在像limps然后调用的情况下,它将有两个元素.
任何人都可以看到更好的数据结构用于此吗?
我使用的是带有外国操作系统的Java程序(韩文/日文等).像FileChooser这样的摆动组件的显示在国外语言中,我需要更改为英语.
java.util.Locale.setDefault(java.util.Locale.ENGLISH);
JFileChooser chooser = new JFileChooser();
chooser.setLocale(Locale.ENGLISH);
Run Code Online (Sandbox Code Playgroud)
文件选择器仍然显示所有内容 - 按钮等在这些外国语言中.知道怎么解决吗?
我的JFilechooser按钮的OK/CANCEL用日语显示.我正在使用日语Windows.如何将其改为英语?
我有一个帖子类,它有点工作,但有一个问题:主键不会增加.
@Entity
@Table(name="posts")
public class Post extends GenericModel{
@Id
@Column(name="post_id")
public int id;
@Column(name="post_situation")
public String situation;
@Column(name="post_date")
public Date date;
@Column(name="post_userid")
public int userid;
@OneToMany(mappedBy="post", cascade=CascadeType.ALL)
public List<Block> blocks;
public Post addBlock(String content, int position){
Block b = new Block(this, content, position);
b.save();
this.blocks.add(b);
this.save();
return this;
}
public Post(String situation, Date date){
this.situation = situation;
this.date = date;
this.userid = 2;
}
}
Run Code Online (Sandbox Code Playgroud)
当我第一次在空表上调用它时,它工作正常,但第二次,我得到PersistenceException occured : org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
post_id列总是有0.任何想法如何解决这个问题?我在地方有@Id注释..
这就是我在我的控制器中的方式:
Post p …Run Code Online (Sandbox Code Playgroud) 我读了一本关于Hibernate的书,我遇到了关于Session对象的以下声明.
....但是如您所知,不建议跨多个请求保持JDBC连接,因为它是一种昂贵的资源.因此,如果我们想要长时间维护Hibernate会话,使其跨越多个重用持久实例的请求,我们希望在不关闭会话的情况下断开每个请求的会话JDBC连接.我们可以在Session接口中使用disconnect()和reconnect()方法来支持这种要求.
断开连接并重新连接JDBC会使它比保持原样更昂贵吗?究竟是什么让资源变得昂贵?
我遇到了两个用于解析文件的不同代码StAX.一个快速的谷歌搜索告诉我,有两种方法可以解析:使用游标API和使用迭代器API.请告诉我两者之间的区别,从开发人员的角度来看哪一个更容易使用.
我正在研究web应用程序.我在我的jsp上调用request.getContextPath(),但奇怪的是我得到了地址/streetshop.
然后我附加一些路径作为request.getContextPath() + "abc"和创建文件夹.
然后创建文件夹D://而不是我的webapplication文件夹.
请告诉我,我想上传一张图片web-application root/images/images.gif.