Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [VB.Net to Java] Function Conversion
New Posts  All Forums:Forum Nav:

[VB.Net to Java] Function Conversion

post #1 of 5
Thread Starter 
Code:
    Public Shared Function GetCIP(ByVal name As String) As String()
        Dim list As ArrayList
        Dim IP As IPAddress
        Try
            list = New ArrayList
            For Each IP In Dns.GetHostAddresses(name)
                list.Add(IP.ToString)
            Next
            Return CType(list.ToArray(GetType(String)), String())
        Catch ex As Exception
            Debug.WriteLine(ex)
            Return New String() {}
        End Try
    End Function
A) What exactly does this do?
B) How can I replicate this in Java? There is no IP type in Java as far as I know. Thanks.
Edited by Lyoko - 5/20/08 at 1:54pm
post #2 of 5
Thread Starter 
Bump
post #3 of 5
RAWR
(13 items)
 
Home Server
(11 items)
 
 
CPUMotherboardGraphicsRAM
i7-4790k msi z97 gaming 7 gtx 760 4gb 32GB GSkill  
Hard DriveHard DriveCoolingOS
Kingston HyperX 3K 120GB SSD Hitachi 2TB Cooler Master Hyper 212+ Windows 8.1 Pro 
MonitorKeyboardPowerCase
Vizio M492-b2 Logitech Wireless  Corsair HX620 NZXT Phantom White 
Mouse
Logitech Wireless 
  hide details  
Reply
RAWR
(13 items)
 
Home Server
(11 items)
 
 
CPUMotherboardGraphicsRAM
i7-4790k msi z97 gaming 7 gtx 760 4gb 32GB GSkill  
Hard DriveHard DriveCoolingOS
Kingston HyperX 3K 120GB SSD Hitachi 2TB Cooler Master Hyper 212+ Windows 8.1 Pro 
MonitorKeyboardPowerCase
Vizio M492-b2 Logitech Wireless  Corsair HX620 NZXT Phantom White 
Mouse
Logitech Wireless 
  hide details  
Reply
post #4 of 5
Quote:
Originally Posted by LyokoHaCk View Post
Code:
    Public Shared Function GetCIP(ByVal name As String) As String()
        Dim list As ArrayList
        Dim IP As IPAddress
        Try
            list = New ArrayList
            For Each IP In Dns.GetHostAddresses(name)
                list.Add(IP.ToString)
            Next
            Return CType(list.ToArray(GetType(String)), String())
        Catch ex As Exception
            Debug.WriteLine(ex)
            Return New String() {}
        End Try
    End Function
A) What exactly does this do?
B) How can I replicate this in Java? There is no IP type in Java as far as I know. Thanks.
It iterates through all IP's that a call to Dns.GetHostAddresses with the function's argument as an argument. For each IP address it converts it to a string and stores it in an arraylist. If it is successful it returns the array representation of the arraylist. If an exception occurs it returns an empty string array. I don't know what the Java equivalent of Dns.GetHostAddresses is, but here's the rest of the code in java

Code:
public String[] GetCIP(String name){
ArrayList<String> list;
ListIterator it;

try{
list = new ArrayList<String>();
it = Dns.GetHostAddresses(name).iterator();
while(it.hasNext)
list.add(it.next().toString());

return list.toArray();
}catch(Exception e){
return new String[0];
}
}
In the code I assume that Dns.GetHostAddresses(String) returns a list of some kind. You will have to replace this with its java equivalent because I don't know what it is. If it doesn't return a list the code will have to change somewhat.

It's been a while since I used java but the above should work
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #5 of 5
Thread Starter 
Thank you both. Repped!
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [VB.Net to Java] Function Conversion