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


Java FileDescriptor类代码示例

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


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

示例1: posixFadviseIfPossible

import java.io.FileDescriptor; //导入依赖的package包/类
@Override
public void posixFadviseIfPossible(String name,
  FileDescriptor fd, long offset, long len, int flags)
      throws NativeIOException {
  if ((len < 0) || (len > Integer.MAX_VALUE)) {
    throw new RuntimeException("invalid length of " + len +
        " passed to posixFadviseIfPossible");
  }
  if ((offset < 0) || (offset > Integer.MAX_VALUE)) {
    throw new RuntimeException("invalid offset of " + offset +
        " passed to posixFadviseIfPossible");
  }
  Stats stats = map.get(name);
  if (stats == null) {
    stats = new Stats(name);
    map.put(name, stats);
  }
  stats.fadvise((int)offset, (int)len, flags);
  super.posixFadviseIfPossible(name, fd, offset, len, flags);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:TestCachingStrategy.java

示例2: write

import java.io.FileDescriptor; //导入依赖的package包/类
/**
 * java.io always writes every byte it's asked to, or fails with an error. (That is, unlike
 * Unix it never just writes as many bytes as happens to be convenient.)
 */
public static void write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws IOException {
    ArrayUtils.checkOffsetAndCount(bytes.length, byteOffset, byteCount);
    if (byteCount == 0) {
        return;
    }
    try {
        while (byteCount > 0) {
            int bytesWritten = Os.write(fd, bytes, byteOffset, byteCount);
            byteCount -= bytesWritten;
            byteOffset += bytesWritten;
        }
    } catch (ErrnoException errnoException) {
        throw new IOException(errnoException);
    }
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:20,代码来源:FileBridge.java

示例3: getOwner

import java.io.FileDescriptor; //导入依赖的package包/类
public static String getOwner(FileDescriptor fd) throws IOException {
	ensureInitialized();
	if (Shell.WINDOWS) {
		String owner = Windows.getOwner(fd);
		owner = stripDomain(owner);
		return owner;
	} else {
		long uid = POSIX.getUIDforFDOwnerforOwner(fd);
		CachedUid cUid = uidCache.get(uid);
		long now = System.currentTimeMillis();
		if (cUid != null && (cUid.timestamp + cacheTimeout) > now) {
			return cUid.username;
		}
		String user = POSIX.getUserName(uid);
		LOG.info("Got UserName " + user + " for UID " + uid + " from the native implementation");
		cUid = new CachedUid(user, now);
		uidCache.put(uid, cUid);
		return user;
	}
}
 
开发者ID:liuhaozzu,项目名称:big_data,代码行数:21,代码来源:NativeIOaa.java

示例4: testStoreTemporaryBarFile2

import java.io.FileDescriptor; //导入依赖的package包/类
/**
 * fsync OFF.
 * FileDescriptor#sync() should never be called.
 * @throws Exception .
 */
@Test
public void testStoreTemporaryBarFile2() throws Exception {
    boolean fsyncEnabled = PersoniumUnitConfig.getFsyncEnabled();
    PersoniumUnitConfig.set(BinaryData.FSYNC_ENABLED, "false");
    try {
        CellEsImpl cell = new CellEsImpl();
        cell.setId("hogeCell");
        BarFileInstaller bfi = Mockito.spy(new BarFileInstaller(cell, "hogeBox", null, null));
        Method method = BarFileInstaller.class.getDeclaredMethod(
                "storeTemporaryBarFile", new Class<?>[] {InputStream.class});
        method.setAccessible(true);
        //any file
        method.invoke(bfi, new FileInputStream("pom.xml"));
        Mockito.verify(bfi, Mockito.never()).sync((FileDescriptor) Mockito.anyObject());
    } finally {
        PersoniumUnitConfig.set(BinaryData.FSYNC_ENABLED, String.valueOf(fsyncEnabled));
    }
}
 
开发者ID:personium,项目名称:personium-core,代码行数:24,代码来源:BarFileValidateTest.java

示例5: dump

import java.io.FileDescriptor; //导入依赖的package包/类
@Override
protected void dump(final FileDescriptor fd, final PrintWriter fout, final String[] args) {
    super.dump(fd, fout, args);

    final Printer p = new PrintWriterPrinter(fout);
    p.println("LatinIME state :");
    p.println("  VersionCode = " + ApplicationUtils.getVersionCode(this));
    p.println("  VersionName = " + ApplicationUtils.getVersionName(this));
    final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
    final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
    p.println("  Keyboard mode = " + keyboardMode);
    final SettingsValues settingsValues = mSettings.getCurrent();
    p.println(settingsValues.dump());
    p.println(mDictionaryFacilitator.dump(this /* context */));
    // TODO: Dump all settings values
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:17,代码来源:LatinIME.java

示例6: decodeSampledBitmapFromDescriptor

import java.io.FileDescriptor; //导入依赖的package包/类
public static Bitmap decodeSampledBitmapFromDescriptor(FileDescriptor fileDescriptor, BitmapSize maxSize, Bitmap.Config config) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inPurgeable = true;
    options.inInputShareable = true;
    BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
    options.inSampleSize = calculateInSampleSize(options, maxSize.getWidth(), maxSize.getHeight());
    options.inJustDecodeBounds = false;
    if (config != null) {
        options.inPreferredConfig = config;
    }
    try {
        return BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
    } catch (Throwable e) {
        LogUtils.e(e.getMessage(), e);
        return null;
    }
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:19,代码来源:BitmapDecoder.java

示例7: dump

import java.io.FileDescriptor; //导入依赖的package包/类
public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
    super.dump(prefix, fd, writer, args);
    writer.print(prefix);
    writer.print("mUri=");
    writer.println(this.mUri);
    writer.print(prefix);
    writer.print("mProjection=");
    writer.println(Arrays.toString(this.mProjection));
    writer.print(prefix);
    writer.print("mSelection=");
    writer.println(this.mSelection);
    writer.print(prefix);
    writer.print("mSelectionArgs=");
    writer.println(Arrays.toString(this.mSelectionArgs));
    writer.print(prefix);
    writer.print("mSortOrder=");
    writer.println(this.mSortOrder);
    writer.print(prefix);
    writer.print("mCursor=");
    writer.println(this.mCursor);
    writer.print(prefix);
    writer.print("mContentChanged=");
    writer.println(this.mContentChanged);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:25,代码来源:CursorLoader.java

示例8: testOpenWithCreate

import java.io.FileDescriptor; //导入依赖的package包/类
@Test (timeout = 30000)
public void testOpenWithCreate() throws Exception {
  if (Path.WINDOWS) {
    return;
  }

  LOG.info("Test creating a file with O_CREAT");
  FileDescriptor fd = NativeIO.POSIX.open(
    new File(TEST_DIR, "testWorkingOpen").getAbsolutePath(),
    NativeIO.POSIX.O_WRONLY | NativeIO.POSIX.O_CREAT, 0700);
  assertNotNull(true);
  assertTrue(fd.valid());
  FileOutputStream fos = new FileOutputStream(fd);
  fos.write("foo".getBytes());
  fos.close();

  assertFalse(fd.valid());

  LOG.info("Test exclusive create");
  try {
    fd = NativeIO.POSIX.open(
      new File(TEST_DIR, "testWorkingOpen").getAbsolutePath(),
      NativeIO.POSIX.O_WRONLY | NativeIO.POSIX.O_CREAT | NativeIO.POSIX.O_EXCL, 0700);
    fail("Was able to create existing file with O_EXCL");
  } catch (NativeIOException nioe) {
    LOG.info("Got expected exception for failed exclusive create", nioe);
    assertEquals(Errno.EEXIST, nioe.getErrno());
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:30,代码来源:TestNativeIO.java

示例9: getOwner

import java.io.FileDescriptor; //导入依赖的package包/类
public static String getOwner(FileDescriptor fd) throws IOException {
  ensureInitialized();
  if (Shell.WINDOWS) {
    String owner = Windows.getOwner(fd);
    owner = stripDomain(owner);
    return owner;
  } else {
    long uid = POSIX.getUIDforFDOwnerforOwner(fd);
    CachedUid cUid = uidCache.get(uid);
    long now = System.currentTimeMillis();
    if (cUid != null && (cUid.timestamp + cacheTimeout) > now) {
      return cUid.username;
    }
    String user = POSIX.getUserName(uid);
    LOG.info("Got UserName " + user + " for UID " + uid
        + " from the native implementation");
    cUid = new CachedUid(user, now);
    uidCache.put(uid, cUid);
    return user;
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:NativeIO.java

示例10: decodeSampledBitmapFromDescriptor

import java.io.FileDescriptor; //导入依赖的package包/类
/**
 * Decode and sample down a bitmap from a file input stream to the requested width and height.
 *
 * @param fileDescriptor The file descriptor to read from
 * @param reqWidth The requested width of the resulting bitmap
 * @param reqHeight The requested height of the resulting bitmap
 * @param cache The ImageCache used to find candidate bitmaps for use with inBitmap
 * @return A bitmap sampled down from the original with the same aspect ratio and dimensions
 *         that are equal to or greater than the requested width and height
 */
public static Bitmap decodeSampledBitmapFromDescriptor(
        FileDescriptor fileDescriptor, int reqWidth, int reqHeight, ImageCache cache) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;

    // If we're running on Honeycomb or newer, try to use inBitmap
    if (Utils.hasHoneycomb()) {
        addInBitmapOptions(options, cache);
    }

    return BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
}
 
开发者ID:jjuiddong,项目名称:Android-Practice,代码行数:32,代码来源:ImageResizer.java

示例11: UnixAsynchronousSocketChannelImpl

import java.io.FileDescriptor; //导入依赖的package包/类
UnixAsynchronousSocketChannelImpl(Port port,
                                  FileDescriptor fd,
                                  InetSocketAddress remote)
    throws IOException
{
    super(port, fd, remote);

    this.fdVal = IOUtil.fdVal(fd);
    IOUtil.configureBlocking(fd, false);

    try {
        port.register(fdVal, this);
    } catch (ShutdownChannelGroupException x) {
        // ShutdownChannelGroupException thrown if we attempt to register a
        // new channel after the group is shutdown
        throw new IOException(x);
    }

    this.port = port;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:UnixAsynchronousSocketChannelImpl.java

示例12: sendFromManagedBuffer

import java.io.FileDescriptor; //导入依赖的package包/类
private int sendFromManagedBuffer(FileDescriptor fd, ByteBuffer bb,
                                 InetSocketAddress target)
    throws IOException
{
    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    boolean preferIPv6 = (family != StandardProtocolFamily.INET);
    int written;
    try {
        written = send0(preferIPv6, fd, bb.array(), bb.arrayOffset() + pos,
                        rem, target.getAddress(), target.getPort());
    } catch (PortUnreachableException pue) {
        if (isConnected())
            throw pue;
        written = rem;
    }
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:DatagramChannelImpl.java

示例13: testFDDoesntLeak

import java.io.FileDescriptor; //导入依赖的package包/类
/**
 * Test that opens and closes a file 10000 times - this would crash with
 * "Too many open files" if we leaked fds using this access pattern.
 */
@Test (timeout = 30000)
public void testFDDoesntLeak() throws IOException {
  if (Path.WINDOWS) {
    return;
  }

  for (int i = 0; i < 10000; i++) {
    FileDescriptor fd = NativeIO.POSIX.open(
      new File(TEST_DIR, "testNoFdLeak").getAbsolutePath(),
      O_WRONLY | O_CREAT, 0700);
    assertNotNull(true);
    assertTrue(fd.valid());
    FileOutputStream fos = new FileOutputStream(fd);
    fos.write("foo".getBytes());
    fos.close();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:22,代码来源:TestNativeIO.java

示例14: getFD

import java.io.FileDescriptor; //导入依赖的package包/类
static cli.System.Net.Sockets.Socket getFD(JNIEnv env, TwoStacksPlainSocketImpl _this) {
    FileDescriptor fdObj = _this.fd;

    if (fdObj == NULL) {
        return null;
    }
    return fdObj.getSocket();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:TwoStacksPlainSocketImpl_c.java

示例15: ServerSocketChannelImpl

import java.io.FileDescriptor; //导入依赖的package包/类
ServerSocketChannelImpl(SelectorProvider sp,
                        FileDescriptor fd,
                        boolean bound)
    throws IOException
{
    super(sp);
    this.fd =  fd;
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ST_INUSE;
    if (bound)
        localAddress = Net.localAddress(fd);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:ServerSocketChannelImpl.java


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