java.io.FileDescriptor Java Examples

The following examples show how to use java.io.FileDescriptor. 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 Project: android-recipes-app   Author: groupsky   File: AsyncTaskLoader.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
    super.dump(prefix, fd, writer, args);
    if (mTask != null) {
        writer.print(prefix); writer.print("mTask="); writer.print(mTask);
                writer.print(" waiting="); writer.println(mTask.waiting);
    }
    if (mCancellingTask != null) {
        writer.print(prefix); writer.print("mCancellingTask="); writer.print(mCancellingTask);
                writer.print(" waiting="); writer.println(mCancellingTask.waiting);
    }
    if (mUpdateThrottle != 0) {
        writer.print(prefix); writer.print("mUpdateThrottle=");
                TimeUtils.formatDuration(mUpdateThrottle, writer);
                writer.print(" mLastLoadCompleteTime=");
                TimeUtils.formatDuration(mLastLoadCompleteTime,
                        SystemClock.uptimeMillis(), writer);
                writer.println();
    }
}
 
Example #2
Source Project: Cake-VPN   Author: ashraf789   File: OpenVpnManagementThread.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void protectFileDescriptor(FileDescriptor fd) {
    try {
        Method getInt = FileDescriptor.class.getDeclaredMethod("getInt$");
        int fdint = (Integer) getInt.invoke(fd);
        // You can even get more evil by parsing toString() and extract the int from that :)
        boolean result = mOpenVPNService.protect(fdint);
        if (!result) VpnStatus.logWarning("Could not protect VPN socket");
        //ParcelFileDescriptor pfd = ParcelFileDescriptor.fromFd(fdint);
        //pfd.close();
        NativeUtils.jniclose(fdint);
        return;
    } catch (NoSuchMethodException | IllegalArgumentException | InvocationTargetException | IllegalAccessException | NullPointerException e) {
        VpnStatus.logException("Failed to retrieve fd from socket (" + fd + ")", e);
    }
    Log.d("Openvpn", "Failed to retrieve fd from socket: " + fd);
}
 
Example #3
Source Project: BambooPlayer   Author: ymback   File: MediaPlayer.java    License: Apache License 2.0 6 votes vote down vote up
/**
  * Sets the data source (file-path or http/rtsp URL) to use.
  *
  * @param path the path of the file, or the http/rtsp URL of the stream you want to play
  * @param keys   AVOption key
  * @param values AVOption value
  * @throws IllegalStateException if it is called in an invalid state
  */
public void setDataSource(String path, String[] keys, String[] values) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
	final Uri uri = Uri.parse(path);
	if ("file".equals(uri.getScheme())) {
		path = uri.getPath();
	}

	final File file = new File(path);
	if (file.exists()) {
		FileInputStream is = new FileInputStream(file);
		FileDescriptor fd = is.getFD();
		setDataSource(fd);
		is.close();
	} else {
		_setDataSource(path, keys, values);
	}
}
 
Example #4
Source Project: jdk8u60   Author: chenghanpeng   File: IOUtil.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static int writeFromNativeBuffer(FileDescriptor fd, ByteBuffer bb,
                                         long position, NativeDispatcher nd)
    throws IOException
{
    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = 0;
    if (rem == 0)
        return 0;
    if (position != -1) {
        written = nd.pwrite(fd,
                            ((DirectBuffer)bb).address() + pos,
                            rem, position);
    } else {
        written = nd.write(fd, ((DirectBuffer)bb).address() + pos, rem);
    }
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #5
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: WindowsAsynchronousFileChannelImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static AsynchronousFileChannel open(FileDescriptor fdo,
                                           boolean reading,
                                           boolean writing,
                                           ThreadPool pool)
    throws IOException
{
    Iocp iocp;
    boolean isDefaultIocp;
    if (pool == null) {
        iocp = DefaultIocpHolder.defaultIocp;
        isDefaultIocp = true;
    } else {
        iocp = new Iocp(null, pool).start();
        isDefaultIocp = false;
    }
    try {
        return new
            WindowsAsynchronousFileChannelImpl(fdo, reading, writing, iocp, isDefaultIocp);
    } catch (IOException x) {
        // error binding to port so need to close it (if created for this channel)
        if (!isDefaultIocp)
            iocp.implClose();
        throw x;
    }
}
 
Example #6
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: IOUtil.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static int writeFromNativeBuffer(FileDescriptor fd, ByteBuffer bb,
                                         long position, NativeDispatcher nd)
    throws IOException
{
    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = 0;
    if (rem == 0)
        return 0;
    if (position != -1) {
        written = nd.pwrite(fd,
                            ((DirectBuffer)bb).address() + pos,
                            rem, position);
    } else {
        written = nd.write(fd, ((DirectBuffer)bb).address() + pos, rem);
    }
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #7
Source Project: jdk8u-dev-jdk   Author: frohoff   File: IOUtil.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static int writeFromNativeBuffer(FileDescriptor fd, ByteBuffer bb,
                                         long position, NativeDispatcher nd)
    throws IOException
{
    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = 0;
    if (rem == 0)
        return 0;
    if (position != -1) {
        written = nd.pwrite(fd,
                            ((DirectBuffer)bb).address() + pos,
                            rem, position);
    } else {
        written = nd.write(fd, ((DirectBuffer)bb).address() + pos, rem);
    }
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #8
Source Project: openjdk-8   Author: bpupadhyaya   File: SctpMultiChannelImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public SctpChannel branch(Association association)
        throws IOException {
    synchronized (stateLock) {
        checkAssociation(association);
        if (!isOpen())
            throw new ClosedChannelException();

        FileDescriptor bFd = SctpNet.branch(fdVal,
                                            association.associationID());
        /* successfully branched, we can now remove it from assoc list */
        removeAssociation(association);

        return new SctpChannelImpl(provider(), bFd, association);
    }
}
 
Example #9
Source Project: openjdk-8-source   Author: keerath   File: SctpMultiChannelImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public SctpChannel branch(Association association)
        throws IOException {
    synchronized (stateLock) {
        checkAssociation(association);
        if (!isOpen())
            throw new ClosedChannelException();

        FileDescriptor bFd = SctpNet.branch(fdVal,
                                            association.associationID());
        /* successfully branched, we can now remove it from assoc list */
        removeAssociation(association);

        return new SctpChannelImpl(provider(), bFd, association);
    }
}
 
Example #10
Source Project: TencentKona-8   Author: Tencent   File: DatagramChannelImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
private int receive(FileDescriptor fd, ByteBuffer dst)
    throws IOException
{
    int pos = dst.position();
    int lim = dst.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);
    if (dst instanceof DirectBuffer && rem > 0)
        return receiveIntoNativeBuffer(fd, dst, rem, pos);

    // Substitute a native buffer. If the supplied buffer is empty
    // we must instead use a nonempty buffer, otherwise the call
    // will not block waiting for a datagram on some platforms.
    int newSize = Math.max(rem, 1);
    ByteBuffer bb = Util.getTemporaryDirectBuffer(newSize);
    try {
        int n = receiveIntoNativeBuffer(fd, bb, newSize, 0);
        bb.flip();
        if (n > 0 && rem > 0)
            dst.put(bb);
        return n;
    } finally {
        Util.releaseTemporaryDirectBuffer(bb);
    }
}
 
Example #11
Source Project: openjdk-8   Author: bpupadhyaya   File: SctpChannelImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor for sockets obtained from branching
 */
public SctpChannelImpl(SelectorProvider provider,
                       FileDescriptor fd,
                       Association association)
        throws IOException {
    super(provider);
    this.fd = fd;
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.CONNECTED;
    port = (Net.localAddress(fd)).getPort();

    if (association != null) { /* branched */
        this.association = association;
    } else { /* obtained from server channel */
        /* Receive COMM_UP */
        ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
        try {
            receive(buf, null, null, true);
        } finally {
            Util.releaseTemporaryDirectBuffer(buf);
        }
    }
}
 
Example #12
Source Project: dragonwell8_jdk   Author: alibaba   File: NetHooks.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invoke prior to connecting an unbound TCP socket.
 */
public static void beforeTcpConnect(FileDescriptor fdObj,
                                    InetAddress address,
                                    int port)
    throws IOException
{
    provider.implBeforeTcpConnect(fdObj, address, port);
}
 
Example #13
Source Project: openjdk-8-source   Author: keerath   File: FileKey.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static FileKey create(FileDescriptor fd) {
    FileKey fk = new FileKey();
    try {
        fk.init(fd);
    } catch (IOException ioe) {
        throw new Error(ioe);
    }
    return fk;
}
 
Example #14
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: NetHooks.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invoke prior to binding a TCP socket.
 */
public static void beforeTcpBind(FileDescriptor fdObj,
                                 InetAddress address,
                                 int port)
    throws IOException
{
    // nothing to do
}
 
Example #15
Source Project: android_9.0.0_r45   Author: lulululbj   File: VoiceInteractionSession.java    License: Apache License 2.0 5 votes vote down vote up
void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
    writer.print(prefix); writer.print("mInterface=");
    writer.println(mInterface.asBinder());
    writer.print(prefix); writer.print("mCallingPackage="); writer.print(mCallingPackage);
    writer.print(" mCallingUid="); UserHandle.formatUid(writer, mCallingUid);
    writer.println();
    writer.print(prefix); writer.print("mCallback=");
    writer.println(mCallback.asBinder());
    if (mExtras != null) {
        writer.print(prefix); writer.print("mExtras=");
        writer.println(mExtras);
    }
}
 
Example #16
Source Project: android_9.0.0_r45   Author: lulululbj   File: DreamManagerService.java    License: Apache License 2.0 5 votes vote down vote up
@Override // Binder call
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
    final long ident = Binder.clearCallingIdentity();
    try {
        dumpInternal(pw);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example #17
Source Project: android_9.0.0_r45   Author: lulululbj   File: VoiceInteractor.java    License: Apache License 2.0 5 votes vote down vote up
void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
    super.dump(prefix, fd, writer, args);
    writer.print(prefix); writer.print("mPrompt="); writer.println(mPrompt);
    if (mExtras != null) {
        writer.print(prefix); writer.print("mExtras="); writer.println(mExtras);
    }
}
 
Example #18
Source Project: android_9.0.0_r45   Author: lulululbj   File: IpSecUdpEncapResponse.java    License: Apache License 2.0 5 votes vote down vote up
public IpSecUdpEncapResponse(int inStatus, int inResourceId, int inPort, FileDescriptor inFd)
        throws IOException {
    if (inStatus == IpSecManager.Status.OK && inFd == null) {
        throw new IllegalArgumentException("Valid status implies FD must be non-null");
    }
    status = inStatus;
    resourceId = inResourceId;
    port = inPort;
    fileDescriptor = (status == IpSecManager.Status.OK) ? ParcelFileDescriptor.dup(inFd) : null;
}
 
Example #19
Source Project: android_9.0.0_r45   Author: lulululbj   File: VoiceInteractionSession.java    License: Apache License 2.0 5 votes vote down vote up
void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
    super.dump(prefix, fd, writer, args);
    writer.print(prefix); writer.print("mPrompt=");
    writer.println(mPrompt);
    if (mOptions != null) {
        writer.print(prefix); writer.println("Options:");
        for (int i=0; i<mOptions.length; i++) {
            VoiceInteractor.PickOptionRequest.Option op = mOptions[i];
            writer.print(prefix); writer.print("  #"); writer.print(i); writer.println(":");
            writer.print(prefix); writer.print("    mLabel=");
            writer.println(op.getLabel());
            writer.print(prefix); writer.print("    mIndex=");
            writer.println(op.getIndex());
            if (op.countSynonyms() > 0) {
                writer.print(prefix); writer.println("    Synonyms:");
                for (int j=0; j<op.countSynonyms(); j++) {
                    writer.print(prefix); writer.print("      #"); writer.print(j);
                    writer.print(": "); writer.println(op.getSynonymAt(j));
                }
            }
            if (op.getExtras() != null) {
                writer.print(prefix); writer.print("    mExtras=");
                writer.println(op.getExtras());
            }
        }
    }
}
 
Example #20
Source Project: Bytecoder   Author: mirkosertic   File: ExtendedSocketOptions.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setOption(FileDescriptor fd, SocketOption<?> option, Object value)
    throws SocketException
{
    throw new UnsupportedOperationException(
            "no extended options: " + option.name());
}
 
Example #21
Source Project: TencentKona-8   Author: Tencent   File: FileLockTable.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates and returns a file lock table for a channel that is connected to
 * the a system-wide map of all file locks for the Java virtual machine.
 */
public static FileLockTable newSharedFileLockTable(Channel channel,
                                                   FileDescriptor fd)
    throws IOException
{
    return new SharedFileLockTable(channel, fd);
}
 
Example #22
Source Project: adt-leanback-support   Author: kingargyle   File: Loader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Print the Loader's state into the given stream.
 *
 * @param prefix Text to print at the front of each line.
 * @param fd The raw file descriptor that the dump is being sent to.
 * @param writer A PrintWriter to which the dump is to be set.
 * @param args Additional arguments to the dump request.
 */
public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
    writer.print(prefix); writer.print("mId="); writer.print(mId);
            writer.print(" mListener="); writer.println(mListener);
    if (mStarted || mContentChanged || mProcessingChange) {
        writer.print(prefix); writer.print("mStarted="); writer.print(mStarted);
                writer.print(" mContentChanged="); writer.print(mContentChanged);
                writer.print(" mProcessingChange="); writer.println(mProcessingChange);
    }
    if (mAbandoned || mReset) {
        writer.print(prefix); writer.print("mAbandoned="); writer.print(mAbandoned);
                writer.print(" mReset="); writer.println(mReset);
    }
}
 
Example #23
Source Project: android_9.0.0_r45   Author: lulululbj   File: DisplayManagerService.java    License: Apache License 2.0 5 votes vote down vote up
@Override // Binder call
public void onShellCommand(FileDescriptor in, FileDescriptor out,
        FileDescriptor err, String[] args, ShellCallback callback,
        ResultReceiver resultReceiver) {
    final long token = Binder.clearCallingIdentity();
    try {
        DisplayManagerShellCommand command = new DisplayManagerShellCommand(this);
        command.exec(this, in, out, err, args, callback, resultReceiver);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
 
Example #24
Source Project: jdk8u-dev-jdk   Author: frohoff   File: ServerSocketChannelImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Accept a connection on a socket.
 *
 * @implNote Wrap native call to allow instrumentation.
 */
private int accept(FileDescriptor ssfd, FileDescriptor newfd,
                   InetSocketAddress[] isaa)
    throws IOException
{
    return accept0(ssfd, newfd, isaa);
}
 
Example #25
Source Project: dragonwell8_jdk   Author: alibaba   File: UnixChannelFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a file channel by opening a file using a dfd/path pair
 */
static FileChannel newFileChannel(int dfd,
                                  UnixPath path,
                                  String pathForPermissionCheck,
                                  Set<? extends OpenOption> options,
                                  int mode)
    throws UnixException
{
    Flags flags = Flags.toFlags(options);

    // default is reading; append => writing
    if (!flags.read && !flags.write) {
        if (flags.append) {
            flags.write = true;
        } else {
            flags.read = true;
        }
    }

    // validation
    if (flags.read && flags.append)
        throw new IllegalArgumentException("READ + APPEND not allowed");
    if (flags.append && flags.truncateExisting)
        throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed");

    FileDescriptor fdObj = open(dfd, path, pathForPermissionCheck, flags, mode);
    return FileChannelImpl.open(fdObj, path.toString(), flags.read, flags.write, flags.append, null);
}
 
Example #26
Source Project: dragonwell8_jdk   Author: alibaba   File: ClosedStreams.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws IOException {

        // close FileDescriptor.in
        (new FileInputStream(FileDescriptor.in)).close();

        // get the inherited channel
        if (System.inheritedChannel() != null) {
            throw new RuntimeException("inherited channel not null - unexpected!");
        }
    }
 
Example #27
Source Project: jdk8u_jdk   Author: JetBrains   File: FileDispatcherImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
FileDescriptor duplicateForMapping(FileDescriptor fd) throws IOException {
    // on Windows we need to keep a handle to the file
    JavaIOFileDescriptorAccess fdAccess =
        SharedSecrets.getJavaIOFileDescriptorAccess();
    FileDescriptor result = new FileDescriptor();
    long handle = duplicateHandle(fdAccess.getHandle(fd));
    fdAccess.setHandle(result, handle);
    return result;
}
 
Example #28
Source Project: TencentKona-8   Author: Tencent   File: AbstractPlainDatagramSocketImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a datagram socket
 */
protected synchronized void create() throws SocketException {
    ResourceManager.beforeUdpCreate();
    fd = new FileDescriptor();
    try {
        datagramSocketCreate();
    } catch (SocketException ioe) {
        ResourceManager.afterUdpClose();
        fd = null;
        throw ioe;
    }
}
 
Example #29
Source Project: dragonwell8_jdk   Author: alibaba   File: FileKey.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static FileKey create(FileDescriptor fd) {
    FileKey fk = new FileKey();
    try {
        fk.init(fd);
    } catch (IOException ioe) {
        throw new Error(ioe);
    }
    return fk;
}
 
Example #30
Source Project: hottub   Author: dsrg-uoft   File: InheritedChannel.java    License: GNU General Public License v2.0 4 votes vote down vote up
InheritedDatagramChannelImpl(SelectorProvider sp,
                             FileDescriptor fd)
    throws IOException
{
    super(sp, fd);
}