Java Code Examples for java.nio.MappedByteBuffer

The following examples show how to use java.nio.MappedByteBuffer. These examples are extracted from open source projects. 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: sasi   Source File: MappedBuffer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void close()
{
    if (!FileUtils.isCleanerAvailable())
        return;

    /*
     * Try forcing the unmapping of pages using undocumented unsafe sun APIs.
     * If this fails (non Sun JVM), we'll have to wait for the GC to finalize the mapping.
     * If this works and a thread tries to access any page, hell will unleash on earth.
     */
    try
    {
        for (MappedByteBuffer segment : pages)
            FileUtils.clean(segment);
    }
    catch (Exception e)
    {
        // This is not supposed to happen
    }
}
 
Example 2
Source Project: bboxdb   Source File: TestUnsafeMemoryHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test the unmapping of memory mapped files (if available in JVM)
 * @throws Exception
 */
@Test(timeout=60000)
public void testUnsafeMemoryHandler() throws Exception {		
	if(! UnsafeMemoryHelper.isDirectMemoryUnmapperAvailable()) {
		return;
	}

	final long oldBytes = UnsafeMemoryHelper.getMappedBytes();
	final long oldSegments = UnsafeMemoryHelper.getMappedSegments();
	
	UnsafeMemoryHelper.unmapMemory(null);
	
	final RandomAccessFile randomAccessFile = new RandomAccessFile("/tmp/mapfile", "rw");
	final MappedByteBuffer mappedBytes = randomAccessFile.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, 100);
	   
	Assert.assertEquals(oldBytes + 100, UnsafeMemoryHelper.getMappedBytes());
	Assert.assertEquals(oldSegments + 1, UnsafeMemoryHelper.getMappedSegments());
	
	randomAccessFile.close();
	UnsafeMemoryHelper.unmapMemory(mappedBytes);

	Assert.assertEquals(oldBytes, UnsafeMemoryHelper.getMappedBytes());
	Assert.assertEquals(oldSegments, UnsafeMemoryHelper.getMappedSegments());
}
 
Example 3
private synchronized void grow() {
    try {
        long start = this.units.size() * Unit.SIZE;
        MappedByteBuffer mmf = this.ch.map(MapMode.READ_WRITE, start, Unit.SIZE * 100);
        this.mmfs.add(mmf);
        mmf.order(ByteOrder.nativeOrder());
        for (int i=0; i<100; i++) {
            Unit ii = new Unit();
            mmf.position(i * Unit.SIZE);
            mmf.limit(mmf.position() + Unit.SIZE);
            ii.buf = mmf.slice();
            ii.addr = UberUtil.getAddress(ii.buf);
            this.units.add(ii);
        }
    }
    catch (Exception ignored) {
        // if it fails then nothing is logged
    }
}
 
Example 4
Source Project: SoftwarePilot   Source File: AutoSelfie.java    License: MIT License 6 votes vote down vote up
byte[] readImg(){
    try {
        //BufferedImage origImage = ImageIO.read(imgPath);
        //ByteArrayOutputStream baos = new ByteArrayOutputStream();
        //ImageIO.write(origImage, "jpg", baos);
        //return baos.toByteArray();

        File file = new File(Environment.getExternalStorageDirectory().getPath()+"/AUAVtmp/fullPic.JPG");
        //File file = new File("../tmp/pictmp.jpg");
        FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel();
        MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
        pic = new byte[buffer.capacity()];
        while(buffer.hasRemaining()){
            int remaining = pic.length;
            if(buffer.remaining() < remaining){
                remaining = buffer.remaining();
            }
            buffer.get(pic, 0, remaining);
        }
        return pic;
    } catch(Exception e){
        e.printStackTrace();
    }
    return new byte[0];
}
 
Example 5
Source Project: jelectrum   Source File: LongMappedBuffer.java    License: MIT License 6 votes vote down vote up
public void putBytes(long position, byte[] buff)
{
  long t1 = System.nanoTime();
  //Assert.assertTrue(position >= 0);
  //Assert.assertTrue(position + buff.length <= total_size);

  int to_write=buff.length;

  int start_file = (int) (position / MAP_SIZE);
  int start_offset = (int) (position % MAP_SIZE);

  MappedByteBuffer map = map_list.get(start_file);

  map.position(start_offset);
  int len = Math.min(to_write, (int) (MAP_SIZE - start_offset));

  map.put(buff, 0, len);
  if (len < to_write)
  {
    map = map_list.get(start_file + 1);
    map.position(0);
    map.put(buff, len, to_write - len);
  }
  TimeRecord.record(t1, "long_map_put_bytes");
}
 
Example 6
Source Project: aeron   Source File: CncFileReader.java    License: Apache License 2.0 6 votes vote down vote up
private CncFileReader(final MappedByteBuffer cncByteBuffer)
{
    this.cncByteBuffer = cncByteBuffer;

    final DirectBuffer cncMetaDataBuffer = createMetaDataBuffer(cncByteBuffer);
    final int cncVersion = cncMetaDataBuffer.getInt(cncVersionOffset(0));

    try
    {
        checkVersion(cncVersion);
    }
    catch (final AeronException e)
    {
        IoUtil.unmap(cncByteBuffer);
        throw e;
    }

    this.cncVersion = cncVersion;
    this.cncSemanticVersion = SemanticVersion.toString(cncVersion);

    this.toDriverBuffer = CncFileDescriptor.createToDriverBuffer(cncByteBuffer, cncMetaDataBuffer);

    this.countersReader = new CountersReader(
        createCountersMetaDataBuffer(cncByteBuffer, cncMetaDataBuffer),
        createCountersValuesBuffer(cncByteBuffer, cncMetaDataBuffer));
}
 
Example 7
Source Project: openjdk-8   Source File: MappedReadBuffer.java    License: GNU General Public License v2.0 6 votes vote down vote up
static ReadBuffer create(RandomAccessFile file) throws IOException {
    FileChannel ch = file.getChannel();
    long size = ch.size();
    // if file size is more than 2 GB and when file mapping is
    // configured (default), use mapped file reader
    if (canUseFileMap() && (size <= Integer.MAX_VALUE)) {
        MappedByteBuffer buf;
        try {
            buf = ch.map(FileChannel.MapMode.READ_ONLY, 0, size);
            ch.close();
            return new MappedReadBuffer(buf);
        } catch (IOException exp) {
            exp.printStackTrace();
            System.err.println("File mapping failed, will use direct read");
            // fall through
        }
    } // else fall through
    return new FileReadBuffer(file);
}
 
Example 8
Source Project: consulo   Source File: MappedBufferWrapper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void flush() {
  MappedByteBuffer buffer = myBuffer;
  if (buffer != null && isDirty()) {
    for (int i = 0; i < MAX_FORCE_ATTEMPTS; i++) {
      try {
        buffer.force();
        myDirty = false;
        break;
      }
      catch (Throwable e) {
        Logger.getInstance(MappedBufferWrapper.class).info(e);
        TimeoutUtil.sleep(10);
      }
    }
  }
}
 
Example 9
Source Project: j2objc   Source File: BufferTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testBug53637() throws Exception {
    MappedByteBuffer mapped = (MappedByteBuffer) allocateMapped(1);
    mapped.get();
    mapped.rewind();
    mapped.get();

    mapped.rewind();
    mapped.mark();
    mapped.get();
    mapped.reset();
    mapped.get();

    mapped.rewind();
    mapped.get();
    mapped.clear();
    mapped.get();

    mapped.rewind();
    mapped.get();
    mapped.flip();
    mapped.get();
}
 
Example 10
Source Project: proxyee-down   Source File: LargeMappedByteBuffer.java    License: Apache License 2.0 6 votes vote down vote up
public final void put(ByteBuffer byteBuffer) throws IOException {
  try {
    int index = getIndex();
    long length = byteBuffer.limit() - byteBuffer.position();
    this.position += length;
    MappedByteBuffer mappedBuffer = bufferList.get(index);
    if (mappedBuffer.remaining() < length) {
      byte[] temp = new byte[mappedBuffer.remaining()];
      byteBuffer.get(temp);
      bufferList.get(index).put(temp);
      bufferList.get(index + 1).put(byteBuffer);
    } else {
      bufferList.get(index).put(byteBuffer);
    }
  } catch (Exception e) {
    throw new IOException(
        "LargeMappedByteBuffer put rawPosition-" + rawPosition + "\tposition-" + position
            + "\tsize-" + size, e);
  }
}
 
Example 11
Source Project: basic-tools   Source File: TestReadFile.java    License: MIT License 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    String smallFilePath = "/Users/renhongqiang/Downloads/work-doc/2000W/demo.txt";
    File file = new File(smallFilePath);


    RandomAccessFile rAccessFile = new RandomAccessFile(file, "r");

    MappedByteBuffer mapBuffer = rAccessFile.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.length());

    int bufferSize = 10;
    byte[] buffer = new byte[10];

    for (int offset = 0; offset < file.length(); offset += bufferSize) {
        int readLength;
        if (offset + bufferSize <= file.length()) {
            readLength = bufferSize;
        } else {
            readLength = (int) (file.length() - offset);
        }
        mapBuffer.get(buffer, 0, readLength);
        System.out.println(new String(buffer, StandardCharsets.UTF_8));
    }


}
 
Example 12
Source Project: aeron   Source File: SamplesUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Map an existing CnC file.
 *
 * @param cncFileVersion to set as value of file.
 * @return the {@link CountersReader} over the CnC file.
 */
public static CountersReader mapCounters(final MutableInteger cncFileVersion)
{
    final File cncFile = CommonContext.newDefaultCncFile();
    System.out.println("Command `n Control file " + cncFile);

    final MappedByteBuffer cncByteBuffer = mapExistingFileReadOnly(cncFile);
    final DirectBuffer cncMetaData = createMetaDataBuffer(cncByteBuffer);
    final int cncVersion = cncMetaData.getInt(cncVersionOffset(0));

    cncFileVersion.set(cncVersion);
    checkVersion(cncVersion);

    return new CountersReader(
        createCountersMetaDataBuffer(cncByteBuffer, cncMetaData),
        createCountersValuesBuffer(cncByteBuffer, cncMetaData));
}
 
Example 13
Source Project: ph-commons   Source File: FileChannelHelper.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private static OutputStream _getMappedOutputStream (@Nonnull @WillNotClose final FileChannel aChannel,
                                                    @Nonnull final File aFile)
{
  try
  {
    // Maximum is Integer.MAX_VALUE even if a long is taken!
    final MappedByteBuffer aBuffer = aChannel.map (MapMode.READ_WRITE, 0, Integer.MAX_VALUE);
    if (LOGGER.isInfoEnabled ())
      LOGGER.info ("Created memory mapped output stream for " + aFile);
    return new ByteBufferOutputStream (aBuffer, false);
  }
  catch (final IOException ex)
  {
    LOGGER.warn ("Failed to create memory mapped output stream for " + aFile, ex);
    return null;
  }
}
 
Example 14
Source Project: j2objc   Source File: FileChannelTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @tests java.nio.channels.FileChannel#map(MapMode,long,long)
 */
public void test_map_ReadWrite() throws IOException {
    MappedByteBuffer mapped = null;
    writeDataToFile(fileOfReadWriteFileChannel);
    mapped = readWriteFileChannel.map(MapMode.READ_WRITE, 0, CONTENT
            .length());

    // put something will change its channel
    ByteBuffer returnByPut = mapped.put(TEST_BYTES);
    assertSame(returnByPut, mapped);
    String checkString = "test" + CONTENT.substring(4);
    ByteBuffer checkBuffer = ByteBuffer.allocate(CONTENT_LENGTH);
    mapped.force();
    readWriteFileChannel.position(0);
    readWriteFileChannel.read(checkBuffer);
    assertEquals(checkString, new String(checkBuffer.array(), "iso8859-1"));

    try {
        mapped.put(("test" + CONTENT).getBytes("iso8859-1"));
        fail("should throw BufferOverflowException.");
    } catch (BufferOverflowException ex) {
        // expected;
    }
}
 
Example 15
@Test
public void writeBytes() throws Exception {
    byte output[] = new byte[bytes.length];

    try (FileChannel fd = FileChannel.open(file.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE)) {
        try (XdrEncodingFileWriter writer = new XdrEncodingFileWriter(new FileChannelWriter(fd, 0))) {
            writer.beginEncoding();
            writer.xdrEncodeOpaque(bytes, bytes.length);
            writer.endEncoding();
        }

        MappedByteBuffer map = fd.map(FileChannel.MapMode.READ_ONLY, 0, fd.size());
        map.order(ByteOrder.BIG_ENDIAN);
        map.get(output);

        assertFalse(map.hasRemaining());
    }

    assertArrayEquals(bytes, output);
}
 
Example 16
Source Project: aeron   Source File: ArchiveTool.java    License: Apache License 2.0 6 votes vote down vote up
private static void printErrors(final PrintStream out, final ArchiveMarkFile markFile)
{
    out.println("Archive error log:");
    CommonContext.printErrorLog(markFile.errorBuffer(), out);

    final MarkFileHeaderDecoder decoder = markFile.decoder();
    decoder.skipControlChannel();
    decoder.skipLocalControlChannel();
    decoder.skipEventsChannel();
    final String aeronDirectory = decoder.aeronDirectory();

    out.println();
    out.println("Aeron driver error log (directory: " + aeronDirectory + "):");
    final File cncFile = new File(aeronDirectory, CncFileDescriptor.CNC_FILE);

    final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, FileChannel.MapMode.READ_ONLY, "cnc");
    final DirectBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
    final int cncVersion = cncMetaDataBuffer.getInt(CncFileDescriptor.cncVersionOffset(0));

    CncFileDescriptor.checkVersion(cncVersion);
    CommonContext.printErrorLog(CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer), out);
}
 
Example 17
Source Project: CrawlerForReader   Source File: FileIOUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 将字节数组写入文件
 *
 * @param file    文件
 * @param bytes   字节数组
 * @param append  是否追加在文件末
 * @param isForce 是否写入文件
 * @return {@code true}: 写入成功<br>{@code false}: 写入失败
 */
public static boolean writeFileFromBytesByMap(final File file,
                                              final byte[] bytes,
                                              final boolean append,
                                              final boolean isForce) {
    if (bytes == null || !createOrExistsFile(file)) return false;
    FileChannel fc = null;
    try {
        fc = new FileOutputStream(file, append).getChannel();
        MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_WRITE, fc.size(), bytes.length);
        mbb.put(bytes);
        if (isForce) mbb.force();
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    } finally {
        CloseUtils.closeIO(fc);
    }
}
 
Example 18
Source Project: offheap-store   Source File: MappedPageSource.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public synchronized MappedPage allocate(int size, boolean thief, boolean victim, OffHeapStorageArea owner) {
  Long address = allocateRegion(size);
  if (address == null) {
    return null;
  }

  try {
    MappedByteBuffer buffer = channel.map(MapMode.READ_WRITE, address, size);
    MappedPage page = new MappedPage(buffer);
    pages.put(page, address);
    return page;
  } catch (IOException e) {
    freeRegion(address);
    LOGGER.warn("Mapping a new file section failed", e);
    return null;
  }
}
 
Example 19
Source Project: buck   Source File: DylibStubContentsScrubber.java    License: Apache License 2.0 6 votes vote down vote up
private static void resetSymbolAddressesInSymbolTable(
    MappedByteBuffer machoBuffer, MachoSymTabCommand symTabCommand) {
  machoBuffer.position(symTabCommand.getSymbolTableOffset());

  for (int i = 0; i < symTabCommand.getNumberOfSymbolTableEntries(); ++i) {
    // struct nlist_64 {
    //     union {
    //         uint32_t  n_strx;  // index into the string table
    //     } n_un;
    //     uint8_t n_type;        // type flag, see below
    //     uint8_t n_sect;        // section number or NO_SECT
    //     uint16_t n_desc;       // see <mach-o/stab.h>
    //     uint64_t n_value;      // value of this symbol (or stab offset)
    // };
    ObjectFileScrubbers.getLittleEndianInt(machoBuffer); // n_strx
    machoBuffer.get(); // n_type
    machoBuffer.get(); // n_sect
    ObjectFileScrubbers.getLittleEndianShort(machoBuffer); // n_desc
    ObjectFileScrubbers.putLittleEndianLong(machoBuffer, 0x0); // n_value
  }
}
 
Example 20
Source Project: titan-hotfix   Source File: ApkSignatureSchemeV2Verifier.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void feedIntoMessageDigests(
        MessageDigest[] mds, long offset, int size) throws IOException {
    long filePosition = mFilePosition + offset;
    MappedByteBuffer buf = mChannel.map(FileChannel.MapMode.READ_ONLY, filePosition, size);

    for (MessageDigest md : mds) {
        buf.position(0);
        md.update(buf);
    }
}
 
Example 21
Source Project: fqueue   Source File: MemoryMappedBlockStore.java    License: Apache License 2.0 5 votes vote down vote up
private MappedByteBuffer getMemoryMappedFileStorage(long maxBytes, String fileName) throws IOException {
    // open the file for read-write
    this.fileName = fileName;
    fileStorage = new RandomAccessFile(fileName, "rw");
    fileStorage.seek(maxBytes);
    fileStorage.getChannel().map(PRIVATE, 0, maxBytes);

    return fileStorage.getChannel().map(PRIVATE, 0, maxBytes);
}
 
Example 22
Source Project: akarnokd-misc   Source File: EditorIDScanner.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    File file = new File(
            "c:\\Program Files (x86)\\Bethesda.net Launcher\\games\\Fallout76\\Data\\SeventySix.esm");

    /*
     * char[4] = 'EDID'
     * uint16 = length
     * uint8[length] = characters
     */
    int i = 1;
    try (PrintWriter out = new PrintWriter(new FileWriter("editorids.txt"))) {
        try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {

            MappedByteBuffer mbb = raf.getChannel().map(MapMode.READ_ONLY, 0, raf.length());
            
            
            while (mbb.remaining() > 0) {
                if (mbb.get() == 'E') {
                    if (mbb.get() == 'D') {
                        if (mbb.get() == 'I') {
                            if (mbb.get() == 'D') {
                                int len = Short.reverseBytes(mbb.getShort()) & 0xFFFF;
                                byte[] data = new byte[len];
                                mbb.get(data);
                                out.println(new String(data, StandardCharsets.ISO_8859_1));
                                if (i % 100 == 0) {
                                    System.out.println("Records so far: " + i);
                                }
                                i++;
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example 23
Source Project: diozero   Source File: SysFsPerfTest.java    License: MIT License 5 votes vote down vote up
private static void testMmapRead(int gpio, int iterations) throws IOException {
	try (FileChannel fc = FileChannel.open(Paths.get("/sys/class/gpio/gpio" + gpio + "/value"),
			StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.SYNC)) {
		MappedByteBuffer mbb = fc.map(MapMode.READ_WRITE, 0, 1);
		long start = System.currentTimeMillis();
		for (int i=0; i<iterations; i++) {
			mbb.get(0);
		}
		long duration = System.currentTimeMillis() - start;
		Logger.info("mmap read: {0.000} ms per iteration", Double.valueOf(duration*1000 / (double) iterations));
	}
}
 
Example 24
Source Project: netbeans   Source File: FastMatcher.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Unmap mapped buffer.
 */
private void unmap(MappedByteBuffer buffer) {
    try {
        Method getCleanerMethod = buffer.getClass().getMethod(
                "cleaner");                                         //NOI18N
        getCleanerMethod.setAccessible(true);
        // sun.misc.Cleaner
        Object cleaner = getCleanerMethod.invoke(buffer);
        cleaner.getClass().getMethod("clean").invoke(cleaner);
    } catch (Exception e) {
    }
}
 
Example 25
Source Project: annoy-java   Source File: ANNIndex.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void getNodeVector(final long nodeOffset, float[] v) {
  MappedByteBuffer nodeBuf = buffers[(int) (nodeOffset / BLOCK_SIZE)];
  int offset = (int) ((nodeOffset % BLOCK_SIZE) + K_NODE_HEADER_STYLE);
  for (int i = 0; i < DIMENSION; i++) {
    v[i] = nodeBuf.getFloat(offset + i * FLOAT_SIZE);
  }
}
 
Example 26
Source Project: imhotep   Source File: FileSerializationBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(int[] a, File file) throws IOException {
    MappedByteBuffer buffer = Files.map(file, FileChannel.MapMode.READ_WRITE, a.length * 4);
    buffer.order(ByteOrder.BIG_ENDIAN);
    IntBuffer intBuffer = buffer.asIntBuffer();
    for (int i = 0; i < a.length; ++i) {
        intBuffer.put(i, a[i]);
    }
}
 
Example 27
private static String readFile(String path) throws IOException {
	try (FileInputStream stream = new FileInputStream(new File(path))) {
		FileChannel fc = stream.getChannel();
		MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
		/* Instead of using default, pass in a decoder. */
		return Charset.defaultCharset().decode(bb).toString();
	}
}
 
Example 28
/**
 * Memory-map the model file in Assets.
 */
public static MappedByteBuffer loadModelFile(Context context, String modelFile)
        throws IOException {
    AssetFileDescriptor fileDescriptor = context.getAssets().openFd(modelFile);
    FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor());
    FileChannel fileChannel = inputStream.getChannel();
    long startOffset = fileDescriptor.getStartOffset();
    long declaredLength = fileDescriptor.getDeclaredLength();
    return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength);
}
 
Example 29
Source Project: jelectrum   Source File: Slopbucket.java    License: MIT License 5 votes vote down vote up
protected void writeLong(long position, long value)
{
  int file = (int) (position / SEGMENT_FILE_SIZE);
  int offset_in_file = (int) (position % SEGMENT_FILE_SIZE);
  MappedByteBuffer mbb = getBufferMap(file);
  synchronized(mbb)
  {
    mbb.position(offset_in_file);
    mbb.putLong(value);
  }
}
 
Example 30
Source Project: jelectrum   Source File: Slopbucket.java    License: MIT License 5 votes vote down vote up
protected Map<String, Integer> loadTroughMap()
{
  TreeMap<String,Integer> map = new TreeMap<>();

  MappedByteBuffer mbb = getBufferMap(0);
  synchronized(mbb)
  {
    for(int i=0; i<MAX_TROUGHS; i++)
    {
      mbb.position( (int)(LOCATION_TROUGH_TABLE_START + (8 + MAX_TROUGH_NAME_LEN) * i));
      long ptr = mbb.getLong();
      byte[] name = new byte[MAX_TROUGH_NAME_LEN];
      mbb.get(name);
      int len =0;
      for(int j=0; (j<MAX_TROUGH_NAME_LEN) && (name[j] != 0); j++)
      {
        len++;
      }
      if (len > 0)
      {
        String name_str = new String(name, 0, len);
        map.put(name_str, i);
      }
      else
      {
        map.put("__FREE", i);
      }
    }
  }
  return map;
}