Ejemplo n.º 1
0
        public EUID(byte[] bytes)
        {
            byte[] newBytes = Extend(bytes);
            long   high     = Longs.FromByteArray(newBytes, 0);
            long   low      = Longs.FromByteArray(newBytes, 8);

            _value = Int128.Create(low, high);
        }
Ejemplo n.º 2
0
        /// <exception cref="System.IO.IOException"/>
        private void LazyOpen()
        {
            if (ch != null)
            {
                return;
            }
            // Load current value.
            byte[] data = null;
            try
            {
                data = Files.ToByteArray(file);
            }
            catch (FileNotFoundException)
            {
            }
            // Expected - this will use default value.
            if (data != null && data.Length != 0)
            {
                if (data.Length != Longs.Bytes)
                {
                    throw new IOException("File " + file + " had invalid length: " + data.Length);
                }
                value = Longs.FromByteArray(data);
            }
            else
            {
                value = defaultVal;
            }
            // Now open file for future writes.
            RandomAccessFile raf = new RandomAccessFile(file, "rw");

            try
            {
                ch = raf.GetChannel();
            }
            finally
            {
                if (ch == null)
                {
                    IOUtils.CloseStream(raf);
                }
            }
        }