javax.sound.sampled.UnsupportedAudioFileException:加载wav文件时无法从输入文件中获取音频输入流

我正在使用java 6 ,我正在尝试加载wav文件,以获得其持续时间如下: public static double getAudioFileDuration(File file) { try { AudioInputStream stream = AudioSystem.getAudioInputStream(file); // At present, ALAW and ULAW encodings must be converted // to PCM_SIGNED before it can be played AudioFormat format = stream.getFormat(); if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) { format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, format.getSampleRate(), format.getSampleSizeInBits(), format.getChannels(), format.getFrameSize(), format.getFrameRate(), true); // big endian […]

Java Email message Parser?

是否有人熟悉Java库,可以帮助解析下面的电子邮件的字段(日期,主题,从,到)? Message-ID: Date: Wed, 6 Mar 2010 12:32:20 -0800 (PST) From: someone@someotherplace.com To: someone@someplace.com Subject: some subject Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-From: one, some X-To: one X-cc: X-bcc: X-Folder: Bob\Inbox X-Origin: Bob-R X-FileName: rbob (Non-Privileged).pst some message

Javagenerics:Collections.max()签名和Comparator

我理解集合的get和put原则 :如果一个方法接受一个集合,它会写一个类型T,参数必须是Collection Collection ,而如果它将从中读取类型T,则参数必须为Collection Collection 。 但有人可以解释Collections.max()签名: public static T max(Collection coll, Comparator comp) 特别是为什么Comparator Comparator代替Comparator Comparator ?

如何使用JPA注释创建连接表?

我需要使用JPA注释在我的数据库中创建一个连接表,结果将是这样的: 到目前为止,我刚刚实施了2个实体 @Entity @Table(name=”USERS”, schema=”ADMIN”) public class User implements Serializable { private static final long serialVersionUID = -1244856316278032177L; @Id @Column(nullable = false) private String userid; @Column(nullable = false) private String password; public String getUserid() { return userid; } public void setUserid(String userid) { this.userid = userid; } public String getPassword() { return password; } public […]

使用AffineTransform将Shape缩放/转换为给定的Rectangle

我正在尝试扩展/翻译java.awt。 使用AffineTransform进行形状 ,以便在定义的边界Rectangle中绘制它。 此外,我想在具有“ 缩放 ”参数的绘图区域中绘制它。 我尝试了各种AffineTransform连接,但我找不到正确的序列。 例如,以下解决方案是错误的: double zoom=(…);/* current zoom */ Rectangle2D viewRect=(…)/** the rectangle where we want to paint the shape */ Shape shape=(…)/* the original shape that should fit in the rectangle viewRect */ Rectangle2D bounds=shape.getBounds2D(); double ratioW=(viewRect.getWidth()/bounds.getWidth()); double ratioH=(viewRect.getHeight()/bounds.getHeight()); AffineTransform transforms[]= { AffineTransform.getScaleInstance(zoom, zoom), AffineTransform.getTranslateInstance(-bounds.getX(),-bounds.getY()), AffineTransform.getTranslateInstance(viewRect.getX(),viewRect.getY()), AffineTransform.getScaleInstance(ratioW, ratioH) }; AffineTransform […]

Java 8中的新java.security.AccessControlException

以前工作的网络代码将java.security.AccessControlException抛入一个完全沙盒化的Java applet 。 Can’t get socket 2255: java.security.AccessControlException: access denied (“java.net.SocketPermission” “50.31.1.13:2255” “connect,resolve”) Oracle改变了什么 – 必须跳出哪些新的安全箍以保持套接字工作? 这在Java 1.7.0_55和所有以前版本的java中都有效。

文本简化工具(Java)

使用Java进行文本简化的最佳工具是什么? 以下是文本简化的示例: John, who was the CEO of a company, played golf. ↓ John played golf. John was the CEO of a company.

Java:如何知道给定类名的jar文件?

给定一个类,例如org.eclipse.ui.views.navigator.ResourceNavigator ,如何找出要使用的jar文件? 我知道它在org.eclipse.ui.ide中,但我怎么能找到它? 编辑 :谢谢你们所有回答的人。 像很多东西一样,似乎有几种方法可以给这只猫上皮。 我希望javadoc包含这个信息。 到目前为止,这里有不同的方法: 没有Internet,Eclipse或NetBeans: for f in `find . -name ‘*.jar’`; do echo $f && jar tvf $f | grep -i $1; done 如果您想使用Eclipse在本地查找: JAR Class Finder插件 类定位器插件 如果你想从互联网上找到你还是没有jar: jarFinder findjar.com

生成泊松和二项式随机数的算法?

我一直在四处寻找,但我不知道该怎么办。 我发现这个页面在最后一段中说: 使用这个简单的配方获得从泊松分布中获取的随机数的简单生成器:如果x 1 ,x 2 ,…是在0和1之间具有均匀分布的随机数序列,则k是第一个整数,其中乘积x 1 ·x 2 ·……·x k + 1 <e -λ 我发现了另一个描述如何生成二项式数的页面 ,但我认为它使用的是泊松生成的近似值,这对我没有帮助。 例如,考虑二项式随机数。 二项式随机数是硬币N次投掷中的头数,其中任意一次投掷的头部概率为p。 如果在区间(0,1)上生成N个均匀随机数并计算小于p的数,则计数是具有参数N和p的二项式随机数。 我知道有库可以做到这一点,但我不能使用它们,只能使用语言提供的标准统一生成器(在本例中为java)。

cURL和HttpURLConnection – 发布JSON数据

如何使用HttpURLConnection发布JSON数据? 我正在尝试这个: HttpURLConnection httpcon = (HttpURLConnection) ((new URL(“a url”).openConnection())); httpcon.setDoOutput(true); httpcon.setRequestProperty(“Content-Type”, “application/json”); httpcon.setRequestProperty(“Accept”, “application/json”); httpcon.setRequestMethod(“POST”); httpcon.connect(); StringReader reader = new StringReader(“{‘value’: 7.5}”); OutputStream os = httpcon.getOutputStream(); char[] buffer = new char[4096]; int bytes_read; while((bytes_read = reader.read(buffer)) != -1) { os.write(buffer, 0, bytes_read);// I am getting compilation error here } os.close(); 我在第14行遇到编译错误。 cURL请求是: curl -H “Accept: […]