java - HTTP 500 error when I try to retrieve the audio file -


i'm trying java program receive audio files using url. when this, gives error:

javax.sound.sampled.unsupportedaudiofileexception: not audio input stream input stream @ javax.sound.sampled.audiosystem.getaudioinputstream(unknown source) @ starter.main(starter.java:21)

when go url in browser, downloads file without .mp3 extension hash used store in database.

import java.io.bufferedinputstream; import java.io.ioexception; import java.io.inputstream; import java.net.httpurlconnection; import java.net.url;  import javax.sound.sampled.audioformat; import javax.sound.sampled.audioinputstream; import javax.sound.sampled.audiosystem; import javax.sound.sampled.dataline; import javax.sound.sampled.sourcedataline;  public class starter {  public static void main(string[] args) {     audioinputstream din = null;     try {         url url = new url("http://www.roblox.com/asset/?id=138738005");         httpurlconnection httpcon = (httpurlconnection) url.openconnection();         inputstream bufferedin = new bufferedinputstream(httpcon.getinputstream());         //audioinputstream in = audiosystem.getaudioinputstream(starter.class.getresourceasstream("338876528.mp3"));         audioinputstream in = audiosystem.getaudioinputstream(bufferedin);         audioformat baseformat = in.getformat();         audioformat decodedformat = new audioformat(                 audioformat.encoding.pcm_signed,                 baseformat.getsamplerate(), 16, baseformat.getchannels(),                 baseformat.getchannels() * 2, baseformat.getsamplerate(),                 false);         din = audiosystem.getaudioinputstream(decodedformat, in);         dataline.info info = new dataline.info(sourcedataline.class, decodedformat);         sourcedataline line = (sourcedataline) audiosystem.getline(info);         if(line != null) {             line.open(decodedformat);             byte[] data = new byte[4096];             // start             line.start();              int nbytesread;             while ((nbytesread = din.read(data, 0, data.length)) != -1) {                 line.write(data, 0, nbytesread);             }             // stop             line.drain();             line.stop();             line.close();             din.close();         }      }     catch(exception e) {         e.printstacktrace();     }     {         if(din != null) {             try { din.close(); } catch(ioexception e) { }         }     } }  } 

the content of http://www.roblox.com/asset/?id=138738005 is

<roblox xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="http://www.roblox.com/roblox.xsd" version="4">   <external>null</external>   <external>nil</external>   <item class="shirtgraphic" referent="rbx0">     <properties>       <content name="graphic">         <url>http://www.roblox.com/asset/?id=138738004</url>       </content>       <string name="name">shirt graphic</string>       <bool name="archivable">true</bool>     </properties>   </item> </roblox> 

so would expect exception when trying treat audio file. file referenced in url tag http://www.roblox.com/asset/?id=138738004 png:

referenced file

so, extracting not here.


Comments