当前位置: 首页>>代码示例>>Java>>正文


Java OsConstants类代码示例

本文整理汇总了Java中android.system.OsConstants的典型用法代码示例。如果您正苦于以下问题:Java OsConstants类的具体用法?Java OsConstants怎么用?Java OsConstants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OsConstants类属于android.system包,在下文中一共展示了OsConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: read

import android.system.OsConstants; //导入依赖的package包/类
/**
 * java.io thinks that a read at EOF is an error and should return -1, contrary to traditional
 * Unix practice where you'd read until you got 0 bytes (and any future read would return -1).
 */
public static int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws IOException {
    ArrayUtils.checkOffsetAndCount(bytes.length, byteOffset, byteCount);
    if (byteCount == 0) {
        return 0;
    }
    try {
        int readCount = Os.read(fd, bytes, byteOffset, byteCount);
        if (readCount == 0) {
            return -1;
        }
        return readCount;
    } catch (ErrnoException errnoException) {
        if (errnoException.errno == OsConstants.EAGAIN) {
            // We return 0 rather than throw if we try to read from an empty non-blocking pipe.
            return 0;
        }
        throw new IOException(errnoException);
    }
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:24,代码来源:FileBridge.java

示例2: fromUri

import android.system.OsConstants; //导入依赖的package包/类
public static DocumentMetadata fromUri(Uri uri, SmbClient client) throws IOException {
final List<String> pathSegments = uri.getPathSegments();
if (pathSegments.isEmpty()) {
  throw new UnsupportedOperationException("Can't load metadata for workgroup or server.");
}

final StructStat stat = client.stat(uri.toString());
  final DirectoryEntry entry = new DirectoryEntry(
      OsConstants.S_ISDIR(stat.st_mode) ? DirectoryEntry.DIR : DirectoryEntry.FILE,
      "",
      uri.getLastPathSegment());
  final DocumentMetadata metadata = new DocumentMetadata(uri, entry);
  metadata.mStat.set(stat);

  return metadata;
}
 
开发者ID:google,项目名称:samba-documents-provider,代码行数:17,代码来源:DocumentMetadata.java

示例3: forwardPacket

import android.system.OsConstants; //导入依赖的package包/类
public void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket) throws VpnNetworkException {
    DatagramSocket dnsSocket = null;
    try {
        // Packets to be sent to the real DNS server will need to be protected from the VPN
        dnsSocket = new DatagramSocket();

        vpnService.protect(dnsSocket);

        dnsSocket.send(outPacket);

        if (parsedPacket != null)
            dnsIn.add(new WaitingOnSocketPacket(dnsSocket, parsedPacket));
        else
            FileHelper.closeOrWarn(dnsSocket, TAG, "handleDnsRequest: Cannot close socket in error");
    } catch (IOException e) {
        FileHelper.closeOrWarn(dnsSocket, TAG, "handleDnsRequest: Cannot close socket in error");
        if (e.getCause() instanceof ErrnoException) {
            ErrnoException errnoExc = (ErrnoException) e.getCause();
            if ((errnoExc.errno == OsConstants.ENETUNREACH) || (errnoExc.errno == OsConstants.EPERM)) {
                throw new VpnNetworkException("Cannot send message:", e);
            }
        }
        Log.w(TAG, "handleDnsRequest: Could not send packet to upstream", e);
        return;
    }
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:27,代码来源:AdVpnThread.java

示例4: testPoll_retryInterrupt

import android.system.OsConstants; //导入依赖的package包/类
@Test
@PrepareForTest({Log.class, Os.class})
public void testPoll_retryInterrupt() throws Exception {
    mockStatic(Log.class);
    mockStatic(Os.class);
    when(Os.poll(any(StructPollfd[].class), anyInt())).then(new Answer<Integer>() {
        @Override
        public Integer answer(InvocationOnMock invocation) throws Throwable {
            // First try fails with EINTR, seconds returns success.
            if (testResult++ == 0) {
                // Android actually sets all OsConstants to 0 when running the
                // unit tests, so this works, but another constant would have
                // exactly the same result.
                throw new ErrnoException("poll", OsConstants.EINTR);
            }
            return 0;
        }
    });

    // poll() will be interrupted first time, so called a second time.
    assertEquals(0, FileHelper.poll(null, 0));
    assertEquals(2, testResult);
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:24,代码来源:FileHelperTest.java

示例5: copyFile

import android.system.OsConstants; //导入依赖的package包/类
private void copyFile() throws IOException, ErrnoException {
    try (InputStream in = assetManager.open(assetNameBuilder.toString(), AssetManager.ACCESS_BUFFER))
    {
        final FileDescriptor fd = Os.open(
                directoryNameBuilder.toString(),
                OsConstants.O_CREAT | OsConstants.O_TRUNC | OsConstants.O_WRONLY,
                OsConstants.S_IROTH | OsConstants.S_IWUSR);

        try (OutputStream out = new FileOutputStream(fd)) {
            int read;
            while ((read = in.read(buffer)) != -1) {
                out.write(buffer, 0, read);
            }
        } finally {
            Os.close(fd);
        }
    }
}
 
开发者ID:chdir,项目名称:aria2-android,代码行数:19,代码来源:WebUiExtractor.java

示例6: dumpProcStatus

import android.system.OsConstants; //导入依赖的package包/类
/**
 * {@code ps}
 */
public static String dumpProcStatus() {
    String[] stat = myProcStat();
    if (stat.length < 27) {
        return "unknown stat string:" + Arrays.toString(stat);
    }
    StringBuilder builder = new StringBuilder(128);
    builder.append("uptime=").append(SystemClock.elapsedRealtime()).append('\t');
    if (Build.VERSION.SDK_INT >= 21) {
        builder.append("CLK_TCK=").append(Os.sysconf(OsConstants._SC_CLK_TCK)).append("HZ\t");
    }
    builder.append("pid=").append(stat[0]).append(',')
            .append("utime=").append(stat[13]).append(',')
            .append("stime=").append(stat[14]).append(',')
            .append("num_threads=").append(stat[19]).append(',')
            .append("starttime=").append(stat[21]);
    return builder.toString();
}
 
开发者ID:succlz123,项目名称:S1-Go,代码行数:21,代码来源:ProcessUtils.java

示例7: isIOExceptionCausedByEPIPE

import android.system.OsConstants; //导入依赖的package包/类
private static boolean isIOExceptionCausedByEPIPE(IOException e) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
        return e.getMessage().contains("EPIPE");
    }

    Throwable cause = e.getCause();
    return cause instanceof ErrnoException && ((ErrnoException) cause).errno == OsConstants.EPIPE;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:9,代码来源:ParcelFileDescriptorUtil.java

示例8: openWriteInternal

import android.system.OsConstants; //导入依赖的package包/类
private ParcelFileDescriptor openWriteInternal(String name, long offsetBytes, long lengthBytes)
        throws IOException {
    // Quick sanity check of state, and allocate a pipe for ourselves. We
    // then do heavy disk allocation outside the lock, but this open pipe
    // will block any attempted install transitions.
    final FileBridge bridge;
    synchronized (mLock) {
        assertPreparedAndNotSealed("openWrite");

        bridge = new FileBridge();
        mBridges.add(bridge);
    }
    try {
        final File target = new File(resolveStageDir(), name);
        // TODO: this should delegate to DCS so the system process avoids
        // holding open FDs into containers.
        final FileDescriptor targetFd = Os.open(target.getAbsolutePath(),
                O_CREAT | O_WRONLY, 0644);
        // If caller specified a total length, allocate it for them. Free up
        // cache space to grow, if needed.
        if (lengthBytes > 0) {
            Os.posix_fallocate(targetFd, 0, lengthBytes);
        }
        if (offsetBytes > 0) {
            Os.lseek(targetFd, offsetBytes, OsConstants.SEEK_SET);
        }
        bridge.setTargetFile(targetFd);
        bridge.start();
        return ParcelFileDescriptor.dup(bridge.getClientSocket());

    } catch (ErrnoException e) {
        throw new IOException(e);
    }
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:35,代码来源:PackageInstallerSession.java

示例9: forwardPacket

import android.system.OsConstants; //导入依赖的package包/类
void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket) throws DaedalusVpnService.VpnNetworkException {
    Socket dnsSocket;
    try {
        // Packets to be sent to the real DNS server will need to be protected from the VPN
        dnsSocket = SocketChannel.open().socket();

        service.protect(dnsSocket);

        SocketAddress address = new InetSocketAddress(outPacket.getAddress(), DNSServerHelper.getPortOrDefault(outPacket.getAddress(), outPacket.getPort()));
        dnsSocket.connect(address, 5000);
        dnsSocket.setSoTimeout(5000);
        Logger.info("TcpProvider: Sending DNS query request");
        DataOutputStream dos = new DataOutputStream(dnsSocket.getOutputStream());
        byte[] packet = processUdpPacket(outPacket, parsedPacket);
        dos.writeShort(packet.length);
        dos.write(packet);
        dos.flush();

        if (parsedPacket != null) {
            dnsIn.add(new TcpProvider.WaitingOnSocketPacket(dnsSocket, parsedPacket));
        } else {
            dnsSocket.close();
        }
    } catch (IOException e) {
        if (e.getCause() instanceof ErrnoException) {
            ErrnoException errnoExc = (ErrnoException) e.getCause();
            if ((errnoExc.errno == OsConstants.ENETUNREACH) || (errnoExc.errno == OsConstants.EPERM)) {
                throw new DaedalusVpnService.VpnNetworkException("Cannot send message:", e);
            }
        }
        Log.w(TAG, "handleDnsRequest: Could not send packet to upstream", e);
    }
}
 
开发者ID:iTXTech,项目名称:Daedalus,代码行数:34,代码来源:TcpProvider.java

示例10: finishIfRunning

import android.system.OsConstants; //导入依赖的package包/类
/** Finish this terminal session by sending SIGKILL to the executablePath. */
public void finishIfRunning() {
    if (isRunning()) {
        try {
            Os.kill(mShellPid, OsConstants.SIGKILL);
        } catch (ErrnoException e) {
            Log.w("neoterm-termux", "Failed sending SIGKILL: " + e.getMessage());
        }
    }
}
 
开发者ID:NeoTerm,项目名称:NeoTerm,代码行数:11,代码来源:TerminalSession.java

示例11: throwErrnoException

import android.system.OsConstants; //导入依赖的package包/类
private void throwErrnoException(IOException e) throws ErrnoException {
  // Hack around that SambaProxyFileCallback throws ErrnoException rather than IOException
  // assuming the underlying cause is an ErrnoException.
  if (e.getCause() instanceof ErrnoException) {
    throw (ErrnoException) e.getCause();
  } else {
    throw new ErrnoException("I/O", OsConstants.EIO, e);
  }
}
 
开发者ID:google,项目名称:samba-documents-provider,代码行数:10,代码来源:SambaProxyFileCallback.java

示例12: poll

import android.system.OsConstants; //导入依赖的package包/类
/**
 * Wrapper around {@link Os#poll(StructPollfd[], int)} that automatically restarts on EINTR
 * While post-Lollipop devices handle that themselves, we need to do this for Lollipop.
 *
 * @param fds     Descriptors and events to wait on
 * @param timeout Timeout. Should be -1 for infinite, as we do not lower the timeout when
 *                retrying due to an interrupt
 * @return The number of fds that have events
 * @throws ErrnoException See {@link Os#poll(StructPollfd[], int)}
 */
public static int poll(StructPollfd[] fds, int timeout) throws ErrnoException, InterruptedException {
    while (true) {
        if (Thread.interrupted())
            throw new InterruptedException();
        try {
            return Os.poll(fds, timeout);
        } catch (ErrnoException e) {
            if (e.errno == OsConstants.EINTR)
                continue;
            throw e;
        }
    }
}
 
开发者ID:julian-klode,项目名称:dns66,代码行数:24,代码来源:FileHelper.java

示例13: fallocateIfSupported

import android.system.OsConstants; //导入依赖的package包/类
@DoNotOptimize
public static void fallocateIfSupported(FileDescriptor fd, long length) throws IOException {
  try {
    Os.posix_fallocate(fd, 0, length);
  } catch (ErrnoException ex) {
    if (ex.errno != OsConstants.EOPNOTSUPP &&
        ex.errno != OsConstants.ENOSYS &&
        ex.errno != OsConstants.EINVAL) {
      throw new IOException(ex.toString(), ex);
    }
  }
}
 
开发者ID:facebook,项目名称:SoLoader,代码行数:13,代码来源:SysUtil.java

示例14: copyDir

import android.system.OsConstants; //导入依赖的package包/类
private void copyDir(String[] assetList) throws IOException, ErrnoException {
    final int dirNameLength = directoryNameBuilder.length();

    Os.mkdir(directoryNameBuilder.toString(), OsConstants.S_IRWXU);

    final int assetBaseNameLength = assetNameBuilder.length();

    for (String asset : assetList) {
        if (theThread.isInterrupted()) {
            throw new IOException("Extraction cancelled");
        }

        assetNameBuilder.setLength(assetBaseNameLength);
        assetNameBuilder.append('/');
        assetNameBuilder.append(asset);

        directoryNameBuilder.setLength(dirNameLength);
        directoryNameBuilder.append(asset);

        String assets[] = assetManager.list(assetNameBuilder.toString());
        if (assets.length == 0) {
            copyFile();
        } else {
            directoryNameBuilder.append('/');

            copyDir(assets);
        }
    }
}
 
开发者ID:chdir,项目名称:aria2-android,代码行数:30,代码来源:WebUiExtractor.java

示例15: ioExceptionIsNoSuchDevice

import android.system.OsConstants; //导入依赖的package包/类
private boolean ioExceptionIsNoSuchDevice(IOException ioException) {
    final Throwable cause = ioException.getCause();
    if (cause instanceof ErrnoException) {
        final ErrnoException errnoException = (ErrnoException) cause;
        return errnoException.errno == OsConstants.ENODEV;
    }
    return false;
}
 
开发者ID:chris-blay,项目名称:android-open-accessory-bridge,代码行数:9,代码来源:BufferHolder.java


注:本文中的android.system.OsConstants类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。