0

Are there any converters available that converts Java code to C#?

I need to convert the below code into C#

String token = new String(""); 
URL url1 =new URL( "http", domain, Integer.valueOf(portnum), "/Workplace/setCredentials?op=getUserToken&userId="+username+"&password="+password +"&verify=true"); 
URLConnection conn1=url1.openConnection(); 
((HttpURLConnection)conn1).setRequestMethod("POST"); 
InputStream contentFileUrlStream = conn1.getInputStream(); 
BufferedReader br = new BufferedReader(new InputStreamReader(contentFileUrlStream)); 
token=br.readLine(); 

String encodedAPIToken = URLEncoder.encode(token); 
String doubleEncodedAPIToken ="ut=" + encodedAPIToken;//.substring(0, encodedAPIToken.length()-1); 
//String doubleEncodedAPIToken ="ut=" + URLEncoder.encode(encodedAPIToken); 
//String userToken = "ut=" + URLEncoder.encode(token, "UTF-8"); //URLEncoder.encode(token); 
String vsId = "vsId=" + URLEncoder.encode(docId.substring(5, docId.length()), "UTF-8"); 
url="http://" + domain + ":" + portnum + "/Workplace/getContent?objectStoreName=RMROS&objectType=document&" + vsId + "&" +doubleEncodedAPIToken; 
String vsId = "vsId=" + URLEncoder.encode(docId.substring(5, docId.length()), "UTF-8"); 
url="http://" + domain + ":" + portnum + "/Workplace/getContent?objectStoreName=RMROS&objectType=document&" + vsId + "&" +doubleEncodedAPIToken; 

Thanks in advance

acadia
  • 2,619
  • 18
  • 55
  • 72

3 Answers3

0

You can try VaryCode Domain no longer exists and no valid snapshots in the Wayback Machine

But you used classes like URLEncoder, BufferedReader etc. that are hard to convert to C# without losing some Java-specific features. For this particular part of code it is insignificant but in prospect you can get some unpredicted behavior of the whole converted program.

Joe White
  • 94,807
  • 60
  • 220
  • 330
0

The code is not very complicated, but if you don't have the time to translate it, you can use a tool like JLCA(Java Language Conversion Assistant 2.0).

Adrian Fâciu
  • 12,414
  • 3
  • 53
  • 68
0

The below links might help:

  1. Microsoft Launches Java-to-C# Converter;
  2. Tangible Software Solutions inc..
Will Marcouiller
  • 23,773
  • 22
  • 96
  • 162