本文整理汇总了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);
}
示例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);
}
}
示例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;
}
}
示例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));
}
}
示例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
}
示例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;
}
}
示例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);
}
示例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());
}
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
示例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);
}