How to identify correct url - url

I have list of URL in txt file I am using it for performance test, since URL were not formed correctly java.IO.exeption were thrown,I would like to know how to check correctness of URL? and whether it is working fine? I have more than 35 K url checking manually will consume lot's of time.

To check whether URL are properly formed try casting the string to an URI object.
eg:
public void validURLs(List<string> urlList)
{
int line = 1;
for(string s : urlList)
{
try
{
URI test = new URI(s);
}
catch(Exception e)
{
System.err.println(s + " is not a valid URL, item " + line);
}
line ++;
}
}

Related

Apache Beam TextIO.Read with line number

Is it possible to get access to line numbers with the lines read into the PCollection from TextIO.Read? For context here, I'm processing a CSV file and need access to the line number for a given line.
If not possible through TextIO.Read it seems like it should be possible using some kind of custom Read or transform, but I'm having trouble figuring out where to begin.
You can use FileIO to read the file manually, where you can determine the line number when you read from the ReadableFile.
A simple solution can look as follows:
p
.apply(FileIO.match().filepattern("/file.csv"))
.apply(FileIO.readMatches())
.apply(FlatMapElements
.into(strings())
.via((FileIO.ReadableFile f) -> {
List<String> result = new ArrayList<>();
try (BufferedReader br = new BufferedReader(Channels.newReader(f.open(), "UTF-8"))) {
int lineNr = 1;
String line = br.readLine();
while (line != null) {
result.add(lineNr + "," + line);
line = br.readLine();
lineNr++;
}
} catch (IOException e) {
throw new RuntimeException("Error while reading", e);
}
return result;
}));
The solution above just prepends the line number to each input line.

File download of server -generated file from button asp.net mvc

OK, this sounds dumb even to me, but I am clearly having a "bad brain day" and need help.
On a button click, I want to generate a file based on parameters taken from 2 ViewData fields and a checkbox control, and have the file be downloaded/displayed, just as you get with a fixed link.
Most of it is going fine, the controller method passes back a file like so: Return File(filePath, "text/csv") - but then what? How do I connect that to the button and have the file download/open dialog come up?
I feel I am missing something really simple. Just calling the controller via ajax seems to do nothing... the code is called but I see no results
***** EDIT: ******
The following gets me a file automatically downloaded, but with the name "download" - I want to offer the user the choice to open or download, and to set the filename - how do I do that?
serialize = function (obj) {
var str = [];
for (var p in obj)
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
return str.join("&");
};
var params = {
ID1: '#ViewData("ID1")',
ID2: '#ViewData("ID2")',
flag: getFlag()
};
var actionUrl = ('#Url.Action("ProduceReport", "Report")');
actionUrl += "/?" + serialize(params);
window.open(actionUrl);
* 2nd edit *
Controller code - this produces a file and returns the path. After the call to ProduceReport The file is there on that path, this I have checked. It is used in production to email the file (works fine).
public FileResult ProduceReport(int ID1, int ID2, bool flag = false)
{
var filePath = ExcelReports.ProduceReportExcel(Models.UserInfo.GetCurrentUserID, ID1, ID2, flag);
return File(filePath,"application/vnd.ms-excel");
}
The acceptable compromise that I found, to at least get the file downloaded. I will have to do further research to see if I can print it automatically.
Javascript:
serialize = function (obj) {
var str = [];
for (var p in obj)
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
return str.join("&");
};
var params = {
ID1: '#ViewData("ID1")',
ID2: '#ViewData("ID2")',
flag: getFlag()
};
var actionUrl = ('#Url.Action("ProduceReport", "Report")');
actionUrl += "/?" + serialize(params);
window.location.href = actionUrl;
Controller: Note 3rd parameter on the File() call
public FileResult ProduceReport(int ID1, int ID2, bool flag = false)
{
var filePath = ExcelReports.ProduceReportExcel(Models.UserInfo.GetCurrentUserID, ID1, ID2, flag);
return File(filePath,"application/vnd.ms-excel",System.IO.Path.GetFileName(filePath));
}

Exception when trying to load .mp3 file in Phaser

I am trying to load a very short .mp3 file in my preload() function like this:
game.load.audio('sword', '$assetPath/swordraw.mp3', true);
As soon as this code gets executed, it crashes with the error
Breaking on exception: Invalid arguments(s)
pointing to a console.warn in Phaser's Loader's fileError function which is as below:
fileError(int index) {
this._fileList[index]['loaded'] = true;
this._fileList[index]['error'] = true;
this.onFileError.dispatch([this._fileList[index]['key'], this._fileList[index]]);
window.console.warn("Phaser.Loader error loading file: "
+ this._fileList[index]['key'] + ' from URL ' + this._fileList[index]['url']);
this.nextFile(index, false);
}
Through the debugger of DartEditor I have seen that for some reason _fileList[10]['url'] (URL for audio file) is picked up as being null here, and that is the cause of the exception (can't concat. null to a string) but why is url null?
I've checked the obvious: the file name is correct and assetPath is certainly initialised correctly since all the other files (which are images) before this load fine. So this seems like an audio file issue of some kind but I can't see what the problem is.
Oh, seems like I found the offender here... https://github.com/playif/play_phaser/blob/ae6a08e5a6eb159149fac01e5831fd8572223a44/lib/loader/loader.dart#L1447
When the Loader is setting up stuff about a newly added file it calls this getAudioUrl if the file is an audio file...
getAudioURL(urls) {
//String extension;
if (urls is String) {
urls = [urls];
}
for (var i = 0; i < urls.length; i++) {
var url = urls[i];
//extension = urls[i].toLowerCase();
//extension = extension.substr((Math.max(0, extension.lastIndexOf(".")) || Infinity) + 1);
if (this.game.device.canPlayAudio(url.split('.').last)) {
//return urls[i];
return url;
}
}
return null;
}
...and as you may gather from the above, the method will return null seemingly if the device cannot play the the type of file supplied. So then, Dartium can't play .mp3s?

Download file Server Error: The handle is invalid?

public ActionResult FileLink(string hashname)
{
try
{
const string basePath = #"\\WINDHOVERDOCUMENTS\";
const string adminSamples = #"Beta\students\";
return File(basePath + adminSamples + hashname, "application/force-download", hashname);
}
catch (Exception)
{
return null; //no file
}
}
This action simple force user to download the file when the action is triggered. Everything works fine locally. But after publishing to server, it gives me this error. Below is the screenshot. Can anyone help? Thank you. please zoom in to see the screenshot. Sorry.
I solved that by reading the file to byte array then return file content result
var fileBytes = System.IO.File.ReadAllBytes(#"\\path\fileP12.zip");
return File(fileBytes, "application/zip", "package.zip");

Save and read file with stream on BlackBerry

Argument 'address' is the string "CepVizyonVersionFile", and after Connector.openDataInputStream(address) the program throws an exception with message:
no ' : ' in URL.
What format should address be in?
public void saveLocal(String fileString, String address) {
try {
DataOutputStream fos = Connector.openDataOutputStream(address); //openFileOutput(address);
fos.write(fileString.getBytes());
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String readLocal(String address, int lenght) {
byte[] buffer = new byte[lenght];
byte[] buffer2;
String str = new String();
try {
DataInputStream fis = Connector.openDataInputStream(address);
int lnght = fis.read(buffer);
buffer2 = new byte[lnght];
fis.close();
for (int i = 0; i < lnght; i++)
buffer2[i] = buffer[i];
str = new String(buffer2);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}
Where do you put your file? If it is on the media card, your address should be like this: "file:///SDCard/"+yourfilename.
The BlackBerry API documentation for Connector has an explanation of the format:
The parameter string that describes the target should conform to the URL format as described in RFC 2396. This takes the general form:
{scheme}:[{target}][{parms}]
where {scheme} is the name of a protocol such as http.
The {target} is normally some kind of network address.
Any {parms} are formed as a series of equates of the form ";x=y". Example: ";type=a".
and the supported schemes are listed as well:
comm
socket
udp
sms
mms
http
https
tls or ssl
Bluetooth Serial Port Profile
Since you want a file, you'll need to take a look at the package documentation for javax.microedition.io.file
The format of the input string used to access a FileConnection through Connector.open() must follow the format for a fully qualified, absolute path file name as described in the file URL format as part of IETF RFCs 1738 & 2396. That RFC dictates that a file URL takes the form:
file://<host>/<path>

Resources