com.sun.jna.Platform Java Examples

The following examples show how to use com.sun.jna.Platform. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TfTool.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
/**
 * This method returns the path to the TF command line program.
 * It relies on the vsts-settings file.
 * This method will throw if no valid path exists.
 */
public static String getValidLocation() {
    // Get the tf command location from file
    final String location = getLocation();
    if (StringUtil.isNullOrEmpty(location)) {
        // tfHome property not set
        throw new ToolException(ToolException.KEY_TF_HOME_NOT_SET);
    }

    final String[] filenames = Platform.isWindows() ? TF_WINDOWS_PROGRAMS : TF_OTHER_PROGRAMS;

    // Verify the path leads to a tf command and exists
    for (final String filename : filenames) {
        if (StringUtils.endsWith(location, filename) && (new File(location)).exists()) {
            return location;
        }
    }

    // The saved location does not point to the tf command
    throw new ToolException(ToolException.KEY_TF_EXE_NOT_FOUND);
}
 
Example #2
Source File: RunActionTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void canRunBinariesAtWorkingDirRoot() throws CommandLineArgException, IOException {
  Path sourceScriptPath = Platform.isWindows() ? Paths.get("script.bat") : Paths.get("script.sh");
  Artifact sourceScript = SourceArtifactImpl.of(PathSourcePath.of(filesystem, sourceScriptPath));

  ImmutableList<String> expectedStderr =
      ImmutableList.of(
          "Message on stderr",
          "arg[--foo]",
          "arg[bar]",
          String.format("PWD: %s", filesystem.getRootPath().toString()),
          "CUSTOM_ENV:");

  RunAction action =
      new RunAction(
          runner.getRegistry(),
          "list",
          CommandLineArgsFactory.from(ImmutableList.of(sourceScript, "--foo", "bar")),
          ImmutableMap.of());

  StepExecutionResult result = runner.runAction(action).getResult();
  assertTrue(result.isSuccess());
  assertEquals(expectedStderr, getStderr(result));
}
 
Example #3
Source File: CloudPlatformTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
@Test
public void test_getCloudPlatform_file_not_present() {

    assumeTrue(Platform.isLinux());

    final CloudPlatform cloudPlatform = new CloudPlatform() {

        @NotNull
        @Override
        File getUuidFile() {
            return new File("/this/file/does/not/exist");
        }
    };

    assertEquals(null, cloudPlatform.getCloudPlatform());
}
 
Example #4
Source File: ContainerEnvironment.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
public String getContainerEnvironment() {

        try {
            if (!Platform.isLinux()) {
                return null;
            }

            //a docker container always has the content "docker" in the cgroup file
            //see https://stackoverflow.com/questions/23513045/
            final File cgroupFile = getCgroupFile();
            if (cgroupFile.exists() && cgroupFile.canRead()) {
                final String content = FileUtils.readFileToString(cgroupFile, StandardCharsets.UTF_8);
                if (content.contains("docker")) {
                    return "Docker";
                }
            }
        } catch (final Exception ex) {
            log.trace("not able to determine if running in container", ex);
        }

        return null;
    }
 
Example #5
Source File: LibraryFinder.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private static String findCoreLibrary() {
    String path="";
    if (Platform.isWindows()) {
    	try {
	    	path = getCPath(true);
	       	path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "InstallDir");
    	} catch (Exception ignored) {
    		try {
		    	path = getCPath(false);
		       	path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "InstallDir");
    		} catch (Exception ignored1) {
    			return "";
    		}
    	}
       	path = path + "CoreFoundation.dll";
       	File f = new File(path);
       	if (f.exists())
       		return path;
    } else if (Platform.isMac()) {
         return "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation";
    }
    return "";
}
 
Example #6
Source File: LibraryFinder.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private static String findMobileLibrary() {
	if (Platform.isWindows()) {
		String path;
	    try {
	    	path = getMDPath(true);
	    	path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "iTunesMobileDeviceDLL");
	    } catch (Exception ignored) {
	    	try {
		    	path = getMDPath(false);
		    	path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "iTunesMobileDeviceDLL");
	    	} catch (Exception ignored1) {
	    		log.info(ignored.getMessage());
	    		return "";
	    	}
		}
    	File f = new File(path);
    	if (f.exists())
    		return path;
	} else {
		if (Platform.isMac()) {
			return "/System/Library/PrivateFrameworks/MobileDevice.framework/MobileDevice";
		}
	}
	return "";
}
 
Example #7
Source File: CloudPlatform.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
public String getCloudPlatform() {
    try {
        if (!Platform.isLinux()) {
            return null;
        }

        //can generate false positives, but seems to be the simplest and least intrusive solution
        //see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html
        final File uuidFile = getUuidFile();
        if (uuidFile.exists() && uuidFile.canRead()) {
            final String content = FileUtils.readFileToString(uuidFile, StandardCharsets.UTF_8);
            if (content.startsWith("ec2") || content.startsWith("EC2")) {
                return "AWS EC2";
            }
        }
    } catch (final Exception ex) {
        log.trace("not able to determine if running on cloud platform", ex);
    }

    return null;
}
 
Example #8
Source File: Processes.java    From Java-Memory-Manipulation with Apache License 2.0 6 votes vote down vote up
public static Process byName(String name) {
	if (Platform.isWindows()) {
		Tlhelp32.PROCESSENTRY32.ByReference entry = new Tlhelp32.PROCESSENTRY32.ByReference();
		Pointer snapshot = Kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPALL.intValue(), 0);
		try {
			while (Kernel32.Process32NextW(snapshot, entry)) {
				String processName = Native.toString(entry.szExeFile);
				if (name.equals(processName)) {
					return byId(entry.th32ProcessID.intValue());
				}
			}
		} finally {
			Kernel32.CloseHandle(snapshot);
		}
	} else if (Platform.isMac() || Platform.isLinux()) {
		return byId(Utils.exec("bash", "-c", "ps -A | grep -m1 \"" + name + "\" | awk '{print $1}'"));
	} else {
		throw new UnsupportedOperationException("Unknown operating system! (" + System.getProperty("os.name") + ")");
	}
	throw new IllegalStateException("Process '" + name + "' was not found. Are you sure its running?");
}
 
Example #9
Source File: ProcessUtil.java    From datax-web with MIT License 6 votes vote down vote up
public static String getProcessId(Process process) {
    long pid = -1;
    Field field;
    if (Platform.isWindows()) {
        try {
            field = process.getClass().getDeclaredField("handle");
            field.setAccessible(true);
            pid = Kernel32.INSTANCE.GetProcessId((Long) field.get(process));
        } catch (Exception ex) {
            logger.error("get process id for windows error {0}", ex);
        }
    } else if (Platform.isLinux() || Platform.isAIX()) {
        try {
            Class<?> clazz = Class.forName("java.lang.UNIXProcess");
            field = clazz.getDeclaredField("pid");
            field.setAccessible(true);
            pid = (Integer) field.get(process);
        } catch (Throwable e) {
            logger.error("get process id for unix error {0}", e);
        }
    }
    return String.valueOf(pid);
}
 
Example #10
Source File: CanonLibraryImpl.java    From canon-sdk-java with MIT License 6 votes vote down vote up
/**
 * <p>Method is called at every call of {@link #edsdkLibrary()}</p>
 */
protected void initLibrary() {
    if (EDSDK == null) {
        synchronized (initLibraryLock) {
            if (EDSDK == null) {
                final String libPath = getLibPath()
                    .orElseThrow(() -> new IllegalStateException("Could not init library, lib path not found"));
                if (Platform.isWindows()) {
                    // no options for now
                    EDSDK = Native.loadLibrary(libPath, EdsdkLibrary.class, new HashMap<>());
                    registerCanonShutdownHook();
                    log.info("Library successfully loaded");
                    return;
                }
                throw new IllegalStateException("Not supported OS: " + Platform.getOSType());
            }
        }
    }
}
 
Example #11
Source File: CanonLibraryImplTest.java    From canon-sdk-java with MIT License 6 votes vote down vote up
@Test
void getLibPath() {
    final CanonLibraryImpl canonLibrary = (CanonLibraryImpl) CanonFactory.canonLibrary();
    if (Platform.is64Bit()) {
        Assertions.assertEquals(DllUtil.DEFAULT_LIB_64_PATH, canonLibrary.getLibPath().get());
    }

    canonLibrary.setArchLibraryToUse(CanonLibrary.ArchLibrary.FORCE_32);
    Assertions.assertEquals(DllUtil.DEFAULT_LIB_32_PATH, canonLibrary.getLibPath().get());

    canonLibrary.setArchLibraryToUse(CanonLibrary.ArchLibrary.FORCE_64);
    Assertions.assertEquals(DllUtil.DEFAULT_LIB_64_PATH, canonLibrary.getLibPath().get());

    System.setProperty("blackdread.cameraframework.library.path", "test");
    Assertions.assertEquals("test", canonLibrary.getLibPath().get());
}
 
Example #12
Source File: Provider.java    From SikuliX1 with MIT License 6 votes vote down vote up
/**
 * Get global hotkey provider for current platform
 *
 * @param useSwingEventQueue whether the provider should be using Swing Event queue or a regular thread
 * @return new instance of Provider, or null if platform is not supported
 * @see X11Provider
 * @see WindowsProvider
 * @see CarbonProvider
 */
public static com.tulskiy.keymaster.common.Provider getCurrentProvider(boolean useSwingEventQueue) {
    com.tulskiy.keymaster.common.Provider provider;
    if (Platform.isX11()) {
        provider = new X11Provider();
    } else if (Platform.isWindows()) {
        provider = new WindowsProvider();
    } else if (Platform.isMac()) {
        provider = new CarbonProvider();
    } else {
        //LOGGER.warn("No suitable provider for " + System.getProperty("os.name"));
        return null;
    }
    provider.setUseSwingEventQueue(useSwingEventQueue);
    provider.init();
    return provider;

}
 
Example #13
Source File: BaseTest.java    From mariadb-connector-j with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Check if server and client are on same host (not using containers).
 *
 * @return true if server and client are really on same host
 */
public boolean hasSameHost() {
  try {
    Statement st = sharedConnection.createStatement();
    ResultSet rs = st.executeQuery("select @@version_compile_os");
    if (rs.next()) {
      if ((rs.getString(1).contains("linux") && Platform.isWindows())
          || (rs.getString(1).contains("win") && Platform.isLinux())) {
        return false;
      }
    }
  } catch (SQLException sqle) {
    // eat
  }
  return true;
}
 
Example #14
Source File: ContextMenuTools.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
public static boolean isAddedToContextMenu() {
    if (!Platform.isWindows()) {
        return false;
    }
    final WinReg.HKEY REG_CLASSES_HKEY = WinReg.HKEY_LOCAL_MACHINE;
    final String REG_CLASSES_PATH = "Software\\Classes\\";
    try {
        if (!Advapi32Util.registryKeyExists(REG_CLASSES_HKEY, REG_CLASSES_PATH + ".swf")) {
            return false;
        }
        String clsName = Advapi32Util.registryGetStringValue(REG_CLASSES_HKEY, REG_CLASSES_PATH + ".swf", "");
        if (clsName == null) {
            return false;
        }
        return Advapi32Util.registryKeyExists(REG_CLASSES_HKEY, REG_CLASSES_PATH + clsName + "\\shell\\ffdec");
    } catch (Win32Exception ex) {
        return false;
    }
}
 
Example #15
Source File: Sha256AuthenticationTest.java    From mariadb-connector-j with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void sha256PluginTestWithoutServerRsaKey() throws SQLException {
  Assume.assumeTrue(!Platform.isWindows() && minVersion(8, 0, 0));

  try (Connection conn =
      DriverManager.getConnection(
          "jdbc:mariadb://"
              + ((hostname == null) ? "localhost" : hostname)
              + ":"
              + port
              + "/"
              + ((database == null) ? "" : database)
              + "?user=sha256User&password=password&allowPublicKeyRetrieval")) {
    Statement stmt = conn.createStatement();

    ResultSet rs = stmt.executeQuery("SELECT '5'");
    Assert.assertTrue(rs.next());
    Assert.assertEquals("5", rs.getString(1));
  }
}
 
Example #16
Source File: RunActionTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException, EvalException {
  ProjectWorkspace workspace =
      TestDataHelper.createProjectWorkspaceForScenario(this, "run_scripts", tmp);
  workspace.setUp();

  BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
  filesystem = TestProjectFilesystems.createProjectFilesystem(tmp.getRoot());
  runner = new TestActionExecutionRunner(filesystem, target);
  scriptPath = Platform.isWindows() ? Paths.get("script.bat") : Paths.get("script.sh");
  script = runner.declareArtifact(scriptPath);

  // Make sure we're testing w/ a BuildArtifact instead of a SourceArtifact
  runner.runAction(
      new WriteAction(
          runner.getRegistry(),
          ImmutableSortedSet.of(),
          ImmutableSortedSet.of(script.asOutputArtifact()),
          filesystem.readFileIfItExists(scriptPath).get(),
          true));
}
 
Example #17
Source File: NativeFileWatcherImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Subclasses should override this method to provide a custom binary to run.
 */
@Nullable
public static File getExecutable() {
  String execPath = System.getProperty(PROPERTY_WATCHER_EXECUTABLE_PATH);
  if (execPath != null) return new File(execPath);

  String[] names = null;
  if (SystemInfo.isWindows) {
    if ("win32-x86".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier.exe"};
    else if ("win32-x86-64".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier64.exe", "fsnotifier.exe"};
  }
  else if (SystemInfo.isMac) {
    names = new String[]{"fsnotifier"};
  }
  else if (SystemInfo.isLinux) {
    if ("linux-x86".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier"};
    else if ("linux-x86-64".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier64"};
    else if ("linux-arm".equals(Platform.RESOURCE_PREFIX)) names = new String[]{"fsnotifier-arm"};
  }
  if (names == null) return PLATFORM_NOT_SUPPORTED;

  return Arrays.stream(names).map(ContainerPathManager.get()::findBinFile).filter(Objects::nonNull).findFirst().orElse(null);
}
 
Example #18
Source File: Processes.java    From Java-Memory-Manipulation with Apache License 2.0 6 votes vote down vote up
public static Process byName(String name) {
	if (Platform.isWindows()) {
		Tlhelp32.PROCESSENTRY32.ByReference entry = new Tlhelp32.PROCESSENTRY32.ByReference();
		Pointer snapshot = Kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPALL.intValue(), 0);
		try {
			while (Kernel32.Process32NextW(snapshot, entry)) {
				String processName = Native.toString(entry.szExeFile);
				if (name.equals(processName)) {
					return byId(entry.th32ProcessID.intValue());
				}
			}
		} finally {
			Kernel32.CloseHandle(snapshot);
		}
	} else if (Platform.isMac() || Platform.isLinux()) {
		return byId(Utils.exec("bash", "-c", "ps -A | grep -m1 \"" + name + "\" | awk '{print $1}'"));
	} else {
		throw new UnsupportedOperationException("Unknown operating system! (" + System.getProperty("os.name") + ")");
	}
	throw new IllegalStateException("Process '" + name + "' was not found. Are you sure its running?");
}
 
Example #19
Source File: Processes.java    From Java-Memory-Manipulation with Apache License 2.0 6 votes vote down vote up
public static Process byId(int id) {
	if ((Platform.isMac() || Platform.isLinux()) && !isSudo()) {
		throw new RuntimeException("You need to run as root/sudo for unix/osx based environments.");
	}
	
	if (Platform.isWindows()) {
		return new Win32Process(id, Kernel32.OpenProcess(0x438, true, id));
	} else if (Platform.isLinux()) {
		return new UnixProcess(id);
	} else if (Platform.isMac()) {
		IntByReference out = new IntByReference();
		if (mac.task_for_pid(mac.mach_task_self(), id, out) != 0) {
			throw new IllegalStateException("Failed to find mach task port for process, ensure you are running as sudo.");
		}
		return new MacProcess(id, out.getValue());
	}
	throw new IllegalStateException("Process " + id + " was not found. Are you sure its running?");
}
 
Example #20
Source File: NativeIOTestCase.java    From vespa with Apache License 2.0 6 votes vote down vote up
@Test
public void requireThatDropFileFromCacheDoesNotThrow() throws IOException {
    File testFile = new File("testfile");
    FileOutputStream output = new FileOutputStream(testFile);
    output.write('t');
    output.flush();
    output.close();
    NativeIO nativeIO = new NativeIO();
    if (Platform.isLinux()) {
        assertTrue(nativeIO.valid());
    } else {
        assertFalse(nativeIO.valid());
        assertEquals("Platform is unsúpported. Only supported on linux.", nativeIO.getError().getMessage());
    }
    nativeIO.dropFileFromCache(output.getFD());
    nativeIO.dropFileFromCache(testFile);
    testFile.delete();
    nativeIO.dropFileFromCache(new File("file.that.does.not.exist"));
}
 
Example #21
Source File: IOSDeviceListenerService.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void run() {
	ANBImplement.getInstance().listen();
	while ((!(Thread.interrupted())) && (Platform.isLinux())) {
		try {
			Thread.sleep(5000L);
		} catch (Exception ignored) {
		}
	}
}
 
Example #22
Source File: JnaDatabase.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void queueEvent(EventHandle eventHandle) throws SQLException {
    try {
        checkConnected();
        final JnaEventHandle jnaEventHandle = validateEventHandle(eventHandle);

        synchronized (getSynchronizationObject()) {
            synchronized (jnaEventHandle) {
                if (Platform.isWindows()) {
                    ((WinFbClientLibrary) clientLibrary).isc_que_events(statusVector, getJnaHandle(),
                            jnaEventHandle.getJnaEventId(),
                            (short) jnaEventHandle.getSize(), jnaEventHandle.getEventBuffer().getValue(),
                            (WinFbClientLibrary.IscEventStdCallback) jnaEventHandle.getCallback(),
                            jnaEventHandle.getResultBuffer().getValue());
                } else {
                    clientLibrary.isc_que_events(statusVector, getJnaHandle(), jnaEventHandle.getJnaEventId(),
                            (short) jnaEventHandle.getSize(), jnaEventHandle.getEventBuffer().getValue(),
                            jnaEventHandle.getCallback(), jnaEventHandle.getResultBuffer().getValue());
                }
            }
            processStatusVector();
        }
    } catch (SQLException e) {
        exceptionListenerDispatcher.errorOccurred(e);
        throw e;
    }
}
 
Example #23
Source File: CLibrary.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private static CLibrary init() {
    if (Platform.isMac() || Platform.isOpenBSD()) {
        return (CLibrary) Native.loadLibrary("c", BSDCLibrary.class);
    } else if (Platform.isFreeBSD()) {
        return (CLibrary) Native.loadLibrary("c", FreeBSDCLibrary.class);
    } else if (Platform.isSolaris()) {
        return (CLibrary) Native.loadLibrary("c", SolarisCLibrary.class);
    } else if (Platform.isLinux()) {
        return (CLibrary) Native.loadLibrary("c", LinuxCLibrary.class);
    } else {
        return (CLibrary) Native.loadLibrary("c", CLibrary.class);
    }
}
 
Example #24
Source File: MapleEngineImpl.java    From Gaalop with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void loadModule(InputStream input) throws MapleEngineException {
	try {
		File tempFile = File.createTempFile("gaalop", ".m");

		try {
			FileOutputStream output = new FileOutputStream(tempFile);

			byte[] buffer = new byte[1024];
			int read;
			while ((read = input.read(buffer)) != -1) {
				output.write(buffer, 0, read);
			}

			output.close();
			if (Platform.isWindows()) {
				evaluate("read " + "\"" + tempFile.getAbsolutePath().replace("\\", "\\\\") + "\";");
			} else {
				evaluate("read \"" + tempFile.getAbsolutePath() + "\";");
			}
		} finally {
			tempFile.delete();
		}
	} catch (IOException e) {
		throw new MapleEngineException("Unable to load module in Maple.", e);
	}
}
 
Example #25
Source File: ScreenAccessor.java    From typometer with Apache License 2.0 5 votes vote down vote up
static ScreenAccessor create(boolean isNative) {
    if (isNative) {
        if (Platform.isWindows()) {
            return new WindowsScreenAccessor();
        }
        if (Platform.isLinux()) {
            return new LinuxScreenAccessor();
        }
    }
    return new AwtRobotScreenAccessor();
}
 
Example #26
Source File: UnixDomainSocket.java    From docker-java with Apache License 2.0 5 votes vote down vote up
UnixDomainSocket(String path) throws IOException {
    if (Platform.isWindows() || Platform.isWindowsCE()) {
        throw new IOException("Unix domain sockets are not supported on Windows");
    }
    sockaddr = new SockAddr(path);
    closeLock.set(false);
    try {
        fd = socket(AF_UNIX, SOCK_STREAM, PROTOCOL);
    } catch (LastErrorException lee) {
        throw new IOException("native socket() failed : " + formatError(lee));
    }
}
 
Example #27
Source File: FbClientDatabaseFactory.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected FbClientLibrary createClientLibrary() {
    try {
        if (Platform.isWindows()) {
            return Native.loadLibrary("fbclient", WinFbClientLibrary.class);
        } else {
            return Native.loadLibrary("fbclient", FbClientLibrary.class);
        }
    } catch (RuntimeException | UnsatisfiedLinkError e) {
        throw new NativeLibraryLoadException("Could not load fbclient", e);
    }
}
 
Example #28
Source File: ApplicationStartupTest.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@Before
public void localSetup() {
    when(mockApplicationNamesInfo.getProductName()).thenReturn(IDEA_NAME);
    PowerMockito.mockStatic(Platform.class, ApplicationNamesInfo.class, AuthHelper.class);
    when(ApplicationNamesInfo.getInstance()).thenReturn(mockApplicationNamesInfo);
    VSTS_DIR.mkdir();
}
 
Example #29
Source File: SystemHelper.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
/**
 * Takes in a path and converts it to Unix standard if Windows OS is detected
 *
 * @param path
 * @return path with forward slashes
 */
public static String getUnixPath(final String path) {
    if (Platform.isWindows()) {
        return path.replace("\\", "/");
    } else {
        return path;
    }
}
 
Example #30
Source File: UnixDomainSocket.java    From docker-java with Apache License 2.0 5 votes vote down vote up
UnixDomainSocket(String path) throws IOException {
    if (Platform.isWindows() || Platform.isWindowsCE()) {
        throw new IOException("Unix domain sockets are not supported on Windows");
    }
    sockaddr = new SockAddr(path);
    closeLock.set(false);
    try {
        fd = socket(AF_UNIX, SOCK_STREAM, PROTOCOL);
    } catch (LastErrorException lee) {
        throw new IOException("native socket() failed : " + formatError(lee));
    }
}