protected virtual void WritePosDict(string filename)
 {
     //new File(filename).getParentFile().mkdirs();
     System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(filename));
     using (Stream os = new FileStream(filename, FileMode.Create, FileAccess.Write))
     {
         DataOutput @out = new OutputStreamDataOutput(os);
         CodecUtil.WriteHeader(@out, BinaryDictionary.POSDICT_HEADER, BinaryDictionary.VERSION);
         @out.WriteVInt32(posDict.Count);
         foreach (string s in posDict)
         {
             if (s == null)
             {
                 @out.WriteByte((byte)0);
                 @out.WriteByte((byte)0);
                 @out.WriteByte((byte)0);
             }
             else
             {
                 string[] data = CSVUtil.Parse(s);
                 if (Debugging.AssertsEnabled)
                 {
                     Debugging.Assert(data.Length == 3, () => "malformed pos/inflection: " + s);
                 }
                 @out.WriteString(data[0]);
                 @out.WriteString(data[1]);
                 @out.WriteString(data[2]);
             }
         }
     }
 }
        protected virtual void WriteDictionary(string filename)
        {
            //new File(filename).getParentFile().mkdirs();
            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(filename));
            using (Stream os = new FileStream(filename, FileMode.Create, FileAccess.Write))
            {
                DataOutput @out = new OutputStreamDataOutput(os);
                CodecUtil.WriteHeader(@out, BinaryDictionary.DICT_HEADER, BinaryDictionary.VERSION);
                @out.WriteVInt32(m_buffer.Position);

                //WritableByteChannel channel = Channels.newChannel(os);
                // Write Buffer
                m_buffer.Flip();  // set position to 0, set limit to current position
                //channel.write(buffer);

                while (m_buffer.HasRemaining)
                {
                    @out.WriteByte(m_buffer.Get());
                }

                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(m_buffer.Remaining == 0L);
                }
            }
        }
        public void Write(string baseDir)
        {
            //string filename = baseDir + System.IO.Path.DirectorySeparatorChar +
            //    typeof(CharacterDefinition).FullName.Replace('.', System.IO.Path.DirectorySeparatorChar) + CharacterDefinition.FILENAME_SUFFIX;

            // LUCENENET specific: we don't need to do a "classpath" output directory, since we
            // are changing the implementation to read files dynamically instead of making the
            // user recompile with the new files.
            string filename = System.IO.Path.Combine(baseDir, typeof(CharacterDefinition).Name + CharacterDefinition.FILENAME_SUFFIX);

            //new File(filename).getParentFile().mkdirs();
            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(baseDir));
            using (Stream os = new FileStream(filename, FileMode.Create, FileAccess.Write))
            {
                DataOutput @out = new OutputStreamDataOutput(os);
                CodecUtil.WriteHeader(@out, CharacterDefinition.HEADER, CharacterDefinition.VERSION);
                @out.WriteBytes(characterCategoryMap, 0, characterCategoryMap.Length);
                for (int i = 0; i < CharacterDefinition.CLASS_COUNT; i++)
                {
                    byte b = (byte)(
                        (invokeMap[i] ? 0x01 : 0x00) |
                        (groupMap[i] ? 0x02 : 0x00)
                        );
                    @out.WriteByte(b);
                }
            }
        }