static void copyExtendedAttributes(int ofd,int nfd){
  NativeBuffer buffer=null;
  try {
    int size=1024;
    buffer=NativeBuffers.getNativeBuffer(size);
    for (; ; ) {
      try {
        size=flistxattr(ofd,buffer.address(),size);
        break;
      }
 catch (      UnixException x) {
        if (x.errno() == ERANGE && size < 32 * 1024) {
          buffer.release();
          size*=2;
          buffer=null;
          buffer=NativeBuffers.getNativeBuffer(size);
          continue;
        }
        return;
      }
    }
    long address=buffer.address();
    int start=0;
    int pos=0;
    while (pos < size) {
      if (unsafe.getByte(address + pos) == 0) {
        int len=pos - start;
        byte[] name=new byte[len];
        unsafe.copyMemory(null,address + start,name,Unsafe.ARRAY_BYTE_BASE_OFFSET,len);
        try {
          copyExtendedAttribute(ofd,name,nfd);
        }
 catch (        UnixException ignore) {
        }
        start=pos + 1;
      }
      pos++;
    }
  }
  finally {
    if (buffer != null)     buffer.release();
  }
}

static void copyExtendedAttributes ( int ofd , int nfd ) { NativeBuffer buffer = null ; try { int size = 1024 ; buffer = NativeBuffers . getNativeBuffer ( size ) ; for ( ; ; ) { try { size = flistxattr ( ofd , buffer . address ( ) , size ) ; break ; } catch ( UnixException x ) { if ( x . errno ( ) == ERANGE && size < 32 * 1024 ) { buffer . release ( ) ; size *= 2 ; buffer = null ; buffer = NativeBuffers . getNativeBuffer ( size ) ; continue ; } return ; } } long address = buffer . address ( ) ; int start = 0 ; int pos = 0 ; while ( pos < size ) { if ( unsafe . getByte ( address + pos ) == 0 ) { int len = pos - start ; byte [ ] name = new byte [ len ] ; unsafe . copyMemory ( null , address + start , name , Unsafe . ARRAY_BYTE_BASE_OFFSET , len ) ; try { copyExtendedAttribute ( ofd , name , nfd ) ; } catch ( UnixException ignore ) { } start = pos + 1 ; } pos ++ ; } } finally { if ( buffer != null ) buffer . release ( ) ; } }
used by copyto / moveto to copy extended attributes from source to target .
