/** * Constructs an {@link AvailablePortIterator}. * <p> * Defaults to using the wildcard address and full port range. */ public AvailablePortIterator() { this(MINIMUM_PORT, MAXIMUM_PORT, NetworkHelper.getWildcardAddress()); }
/** * Construct a new {@link JavaVirtualMachine}. * This constructor is private as the {@link JavaVirtualMachine} * platform is a singleton as there is only one local JVM. */ private JavaVirtualMachine() { super("Java Virtual Machine"); // ----- establish InetAddress of the LocalPlatform ----- // attempt to use the system property that may have been defined // (in the future we may use a PlatformAddress Option to achieve this) String addressSystemProperty = System.getProperty("bedrock.runtime.address"); if (addressSystemProperty == null) { this.address = NetworkHelper.getFeasibleLocalHost(); } else { try { this.address = InetAddress.getByName(addressSystemProperty); } catch (UnknownHostException e) { // TODO: log that the specified address can't be resolved, defaulting to the feasible localhost this.address = NetworkHelper.getFeasibleLocalHost(); } } }
/** * Attempt to recursively delete the specified file or folder. * * @param file a file representing the File or Folder to delete * * @return true if all files/folders have been deleted, false if only * partial removal occurred */ public static boolean recursiveDelete(File file) { if (file != null && file.exists()) { if (file.isDirectory()) { for (File child : file.listFiles()) { if (!recursiveDelete(child)) { return false; } } } return file.delete(); } else { return true; } }
addFolderToZip(file, parent + file.getName(), zip); addFileToZip(file, parentFolderName, zip);
/** * Constructs a local {@link TransportAddress}, choosing a port from the * {@link AvailablePortIterator}. * * @param ports the available ports */ public TransportAddress(AvailablePortIterator ports) { // NOTE: Currently Java Debugging only supports IPv4 on the server-side so we must // filter the AvailablePortIterator addresses into those that are IPv4 this(NetworkHelper.getInetAddresses(ports.getInetAddresses(), NetworkHelper.IPv4_ADDRESS).iterator().next(), new Capture<>(ports)); }
/** * Obtains the {@link InetAddress} on which the {@link SocketBasedRemoteChannelServer} * will accept connections (based on a specific {@link Predicate}) * * @param predicate the {@link Predicate} to filter {@link InetAddress}es * (or <code>null</code> indicating the default is acceptable) * * @return the {@link InetAddress} */ public synchronized InetAddress getInetAddress(Predicate<InetAddress> predicate) { if (serverSocket != null) { try { predicate = predicate == null ? NetworkHelper.DEFAULT_ADDRESS : predicate; InetAddress inetAddress = NetworkHelper.getInetAddress(predicate); // when the specific inetAddess is not available, use the server socket return inetAddress == null ? serverSocket.getInetAddress() : inetAddress; } catch (SocketException e) { return serverSocket.getInetAddress(); } } else { throw new IllegalStateException("Server is closed"); } }
/** * Acquires the first {@link InetAddress} (of the machine on which this code is executing) * that matches the specified {@link Predicate}. * * @param predicate the {@link InetAddress} {@link Predicate} * * @return an {@link InetAddress} or <code>null</code> if no matching {@link InetAddress} * * @throws SocketException when an {@link InetAddress} is not available */ public static InetAddress getInetAddress(Predicate<? super InetAddress> predicate) throws SocketException { for (NetworkInterface networkInterface : getNetworkInterfaces(Predicates.<NetworkInterface>always())) { for (Enumeration addresses = networkInterface.getInetAddresses(); addresses.hasMoreElements(); ) { InetAddress address = (InetAddress) addresses.nextElement(); if (predicate.test(address)) { return address; } } } return null; }
addFolderToZip(file, parent + file.getName(), zip); addFileToZip(file, parentFolderName, zip);
/** * Construct a new {@link JavaVirtualMachine}. * This constructor is private as the {@link JavaVirtualMachine} * platform is a singleton as there is only one local JVM. */ private JavaVirtualMachine() { super("Java Virtual Machine"); // ----- establish InetAddress of the LocalPlatform ----- // attempt to use the system property that may have been defined // (in the future we may use a PlatformAddress Option to achieve this) String addressSystemProperty = System.getProperty("bedrock.runtime.address"); if (addressSystemProperty == null) { this.address = NetworkHelper.getFeasibleLocalHost(); } else { try { this.address = InetAddress.getByName(addressSystemProperty); } catch (UnknownHostException e) { // TODO: log that the specified address can't be resolved, defaulting to the feasible localhost this.address = NetworkHelper.getFeasibleLocalHost(); } } }
/** * Constructs an {@link AvailablePortIterator} * <p> * Defaults to using the wildcard address and a starting port. * * @param portRangeStart the port at which to start scanning (inclusive) */ public AvailablePortIterator(int portRangeStart) { this(portRangeStart, MAXIMUM_PORT, NetworkHelper.getWildcardAddress()); }
/** * Constructs a local {@link TransportAddress}, choosing a port from the * {@link AvailablePortIterator}. * * @param ports the available ports */ public TransportAddress(AvailablePortIterator ports) { // NOTE: Currently Java Debugging only supports IPv4 on the server-side so we must // filter the AvailablePortIterator addresses into those that are IPv4 this(NetworkHelper.getInetAddresses(ports.getInetAddresses(), NetworkHelper.IPv4_ADDRESS).iterator().next(), new Capture<>(ports)); }
/** * Attempt to recursively delete the specified file or folder. * * @param file a file representing the File or Folder to delete * * @return true if all files/folders have been deleted, false if only * partial removal occurred */ public static boolean recursiveDelete(File file) { if (file != null && file.exists()) { if (file.isDirectory()) { for (File child : file.listFiles()) { if (!recursiveDelete(child)) { return false; } } } return file.delete(); } else { return true; } }
/** * Obtains the {@link InetAddress} on which the {@link SocketBasedRemoteChannelServer} * will accept connections (based on a specific {@link Predicate}) * * @param predicate the {@link Predicate} to filter {@link InetAddress}es * (or <code>null</code> indicating the default is acceptable) * * @return the {@link InetAddress} */ public synchronized InetAddress getInetAddress(Predicate<InetAddress> predicate) { if (serverSocket != null) { try { predicate = predicate == null ? NetworkHelper.DEFAULT_ADDRESS : predicate; InetAddress inetAddress = NetworkHelper.getInetAddress(predicate); // when the specific inetAddess is not available, use the server socket return inetAddress == null ? serverSocket.getInetAddress() : inetAddress; } catch (SocketException e) { return serverSocket.getInetAddress(); } } else { throw new IllegalStateException("Server is closed"); } }
/** * Acquires the first {@link InetAddress} (of the machine on which this code is executing) * that matches the specified {@link Predicate}. * * @param predicate the {@link InetAddress} {@link Predicate} * * @return an {@link InetAddress} or <code>null</code> if no matching {@link InetAddress} * * @throws SocketException when an {@link InetAddress} is not available */ public static InetAddress getInetAddress(Predicate<? super InetAddress> predicate) throws SocketException { for (NetworkInterface networkInterface : getNetworkInterfaces(Predicates.<NetworkInterface>always())) { for (Enumeration addresses = networkInterface.getInetAddresses(); addresses.hasMoreElements(); ) { InetAddress address = (InetAddress) addresses.nextElement(); if (predicate.test(address)) { return address; } } } return null; }
addFolderToZip(file, baseFolderName, zip); addFileToZip(file, baseFolderName, zip);
/** * Constructs an {@link AvailablePortIterator}. * <p> * Defaults to using the wildcard address with the specified port range. * * @param portRangeStart the port at which to start scanning (inclusive) * @param portRangeEnd the port at which to destroy scanning (inclusive) */ public AvailablePortIterator(int portRangeStart, int portRangeEnd) { this(portRangeStart, portRangeEnd, NetworkHelper.getWildcardAddress()); }
addFolderToZip(file, baseFolderName, zip); addFileToZip(file, baseFolderName, zip);
/** * Constructs an {@link AvailablePortIterator} * <p> * Defaults to using the wildcard address and a starting port. * * @param portRangeStart the port at which to start scanning (inclusive) */ public AvailablePortIterator(int portRangeStart) { this(portRangeStart, MAXIMUM_PORT, NetworkHelper.getWildcardAddress()); }
/** * Constructs an {@link AvailablePortIterator}. * <p> * Defaults to using the wildcard address and full port range. */ public AvailablePortIterator() { this(MINIMUM_PORT, MAXIMUM_PORT, NetworkHelper.getWildcardAddress()); }
/** * Constructs an {@link AvailablePortIterator}. * <p> * Defaults to using the wildcard address with the specified port range. * * @param portRangeStart the port at which to start scanning (inclusive) * @param portRangeEnd the port at which to destroy scanning (inclusive) */ public AvailablePortIterator(int portRangeStart, int portRangeEnd) { this(portRangeStart, portRangeEnd, NetworkHelper.getWildcardAddress()); }