(String FileName)
| 152 | } |
| 153 | |
| 154 | private static void ByBuffer_URL(String FileName) throws Exception |
| 155 | { |
| 156 | String Amazon_S3_Date = new String(); // Amazon only |
| 157 | String Amazon_S3_Authorization = new String(); // Amazon only |
| 158 | |
| 159 | // Parsing user input |
| 160 | FileName = FileName.replace(" ", "%20"); |
| 161 | int FileName_Amazon_S3_End = FileName.indexOf("@s3.amazonaws.com/"); //Testing if Amazon is used and a AccessKeyId/SecretAccessKey is provided, TODO: use a less ugly method |
| 162 | if (FileName_Amazon_S3_End != -1) |
| 163 | { |
| 164 | // Amazon only, computing the Authorization value |
| 165 | // See http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html |
| 166 | int FileName_Amazon_S3_Begin = FileName.indexOf("://") + 3; |
| 167 | int FileName_Amazon_S3_Middle = FileName.indexOf(":", FileName_Amazon_S3_Begin); |
| 168 | String Amazon_S3_AWSAccessKeyId = FileName.substring(FileName_Amazon_S3_Begin, FileName_Amazon_S3_Middle); |
| 169 | String Amazon_S3_AWSSecretAccessKey = FileName.substring(FileName_Amazon_S3_Middle + 1, FileName_Amazon_S3_End); |
| 170 | FileName = FileName.replace(FileName.substring(FileName_Amazon_S3_Begin, FileName_Amazon_S3_End + 1), new String()); |
| 171 | Amazon_S3_Date = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US).format(new Date()); |
| 172 | String Amazon_S3_ToSign = "GET\n\n\n"+Amazon_S3_Date+"\n"+new URL(FileName).getPath(); |
| 173 | Amazon_S3_Authorization = "AWS "+Amazon_S3_AWSAccessKeyId+":"+calculateHmacSHA1(Amazon_S3_ToSign, Amazon_S3_AWSSecretAccessKey); |
| 174 | } |
| 175 | URL FileUrl = new URL(FileName); |
| 176 | |
| 177 | //From: preparing an example file for reading |
| 178 | HttpURLConnection HttpFrom = (HttpURLConnection ) FileUrl.openConnection(); |
| 179 | if (!Amazon_S3_Authorization.isEmpty()) |
| 180 | { |
| 181 | HttpFrom.setRequestProperty("Date", Amazon_S3_Date); // Amazon only |
| 182 | HttpFrom.setRequestProperty("Authorization", Amazon_S3_Authorization); // Amazon only |
| 183 | } |
| 184 | HttpFrom.connect(); |
| 185 | if (HttpFrom.getResponseCode() != 200) |
| 186 | { |
| 187 | java.util.Scanner S = new java.util.Scanner(HttpFrom.getErrorStream()); |
| 188 | S.useDelimiter("\\Z"); |
| 189 | System.out.println(S.next()); |
| 190 | return; |
| 191 | } |
| 192 | InputStream From = HttpFrom.getInputStream(); |
| 193 | long From_Length = Long.parseLong(HttpFrom.getHeaderField("Content-Length")); //.getContentLengthLong(), for 2GB+ file support is available only in Java 7 and lot of distros have Java 6 |
| 194 | |
| 195 | //From: preparing a memory buffer for reading |
| 196 | byte[] From_Buffer = new byte[64*1024]; |
| 197 | int From_Buffer_Size; //The size of the read file buffer |
| 198 | |
| 199 | //Initializing MediaInfo |
| 200 | MediaInfo MI = new MediaInfo(); |
| 201 | |
| 202 | //Preparing to fill MediaInfo with a buffer |
| 203 | MI.Open_Buffer_Init(From_Length, 0); |
| 204 | |
| 205 | //The parsing loop |
| 206 | do |
| 207 | { |
| 208 | //Reading data somewhere, do what you want for this. |
| 209 | From_Buffer_Size = From.read(From_Buffer); |
| 210 | |
| 211 | //Sending the buffer to MediaInfo |
no test coverage detected