DELETE COPIED FILE'S LINE NUMBER

论坛里面的代码需要拿来使用的时候发现很多行号,很不方便。
试着写了很简单的程序进行处理,主要应用到JAVA 的输入输出流。

以下是所有源码:


package test.deleteNum;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
* 写一个公用的方法,用来去除复制过来代码前面的数字和点点。
*
* @author QHB1205370
*
*/
public class DeleteNumUtil {

/**
*
* @param file
* 需要处理的文件。
* @throws IOException
*/
public static void updateFile(String inputfile, String outputfile)
throws IOException {

InputStream in = new FileInputStream(inputfile);
InputStreamReader isr = new InputStreamReader(in, "GBK");
BufferedReader reader = new BufferedReader(isr);

FileWriter writer = new FileWriter(outputfile);
BufferedWriter br = new BufferedWriter(writer);

String str = null;
while ((str = reader.readLine()) != null) {
str = getNewLine(str);
br.write(str);
br.newLine();
br.flush();
}
reader.close();
br.close();
writer.close();

}

/**
* 修改每行的数据文件,把每行前面的行号去掉。
*
* @param str
* @return
*/
public static String getNewLine(String str) {
String newLine = null;
newLine = str.substring(str.indexOf(".") + 1);
return newLine;
}

// test
public static void main(String[] args) throws IOException {

String inputfile = "e:\\test.txt";
String outputfile = "e:\\another.txt";
updateFile(inputfile, outputfile);
System.out.println("文件已经重新生成。");
}

}
根据上面代码再结合下面代码写出完整的文本文档管理 // // MODULE: TextDocument.cpp // // PURPOSE: Basic implementation of a text data-sequence class // // NOTES: www.catch22.net // #define STRICT #define WIN32_LEAN_AND_MEAN #include <windows.h> #include "TextDocument.h" #include "TextView.h" #include "Unicode.h" struct _BOM_LOOKUP BOMLOOK[] = { // define longest headers first { 0x0000FEFF, 4, NCP_UTF32 }, { 0xFFFE0000, 4, NCP_UTF32BE }, { 0xBFBBEF, 3, NCP_UTF8 }, { 0xFFFE, 2, NCP_UTF16BE }, { 0xFEFF, 2, NCP_UTF16 }, { 0, 0, NCP_ASCII }, }; // // TextDocument constructor // TextDocument::TextDocument() { // buffer = 0; m_nDocLength_bytes = 0; m_nDocLength_chars = 0; m_pLineBuf_byte = 0; m_pLineBuf_char = 0; m_nNumLines = 0; m_nFileFormat = NCP_ASCII; m_nHeaderSize = 0; } // // TextDocument destructor // TextDocument::~TextDocument() { clear(); } // // Initialize the TextDocument with the specified file // bool TextDocument::init(TCHAR *filename) { HANDLE hFile; hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); if(hFile == INVALID_HANDLE_VALUE) return false; return init(hFile); } // // Initialize using a file-handle // bool TextDocument::init(HANDLE hFile) { ULONG numread; char *buffer; if((m_nDocLength_bytes = GetFileSize(hFile, 0)) == 0) return false; // allocate new file-buffer if((buffer = new char[m_nDocLength_bytes]) == 0) return false; // read entire file into memory ReadFile(hFile, buffer, m_nDocLength_bytes, &numread, 0); m_seq.init((BYTE *)buffer, m_nDocLength_bytes); // try to detect if this is an ascii/unicode/utf8 file m_nFileFormat = detect_file_format(&m_nHeaderSize); // work out where each line of text starts if(!init_linebuffer()) clear(); CloseHandle(hFile); delete[] buffer; return true; } // Initialize the TextDocument with the specified file // /*bool TextDocument::save(TCHAR *filename) { HANDLE hFile; hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); if(hFile == INVALID_HANDLE_VALUE) return false; CloseHandle(hFile); return true; }*/ // // Parse the file lo // // // From the unicode.org FAQ: // // 00 00 FE FF UTF-32, big-endian // FF FE 00 00 UTF-32, little-endian // FE FF UTF-16, big-endian // FF FE UTF-16, little-endian // EF BB BF UTF-8 // // Match the first x bytes of the file against the // Byte-Order-Mark (BOM) lookup table // int TextDocument::detect_file_format(int *m_nHeaderSize) { BYTE header[4] = { 0 }; m_seq.render(0, header, 4); for(int i = 0; BOMLOOK[i].len; i++) { if(m_nDocLength_bytes >= BOMLOOK[i].len && memcmp(header, &BOMLOOK[i].bom, BOMLOOK[i].len) == 0) { *m_nHeaderSize = BOMLOOK[i].len; return BOMLOOK[i].type; } } *m_nHeaderSize = 0; return NCP_ASCII; // default to ASCII } // // Empty the data-TextDocument // bool TextDocument::clear() { m_seq.clear(); m_nDocLength_bytes = 0; if(m_pLineBuf_byte) { delete[] m_pLineBuf_byte; m_pLineBuf_byte = 0; } if(m_pLineBuf_char) { delete[] m_pLineBuf_char; m_pLineBuf_char = 0; } m_nNumLines = 0; return true; } bool TextDocument::EmptyDoc() { clear(); m_seq.init(); // this is not robust. it's just to get the thing // up-and-running until I write a proper line-buffer mananger m_pLineBuf_byte = new ULONG[0x1000]; m_pLineBuf_char = new ULONG[0x1000]; m_pLineBuf_byte[0] = 0; m_pLineBuf_char[0] = 0; return true; } // // Return a UTF-32 character value // int TextDocument::getchar(ULONG offset, ULONG lenbytes, ULONG *pch32) { // BYTE *rawdata = (BYTE *)(buffer + offset + m_nHeaderSize); BYTE rawdata[16]; lenbytes = min(16, lenbytes); m_seq.render(offset+ m_nHeaderSize, rawdata, lenbytes); #ifdef UNICODE UTF16 *rawdata_w = (UTF16 *)rawdata;//(WCHAR*)(buffer + offset + m_nHeaderSize); WCHAR ch16; size_t ch32len = 1; switch(m_nFileFormat) { case NCP_ASCII: MultiByteToWideChar(CP_ACP, 0, (CCHAR*)rawdata, 1, &ch16, 1); *pch32 = ch16; return 1; case NCP_UTF16: return utf16_to_utf32(rawdata_w, lenbytes / 2, pch32, &ch32len) * sizeof(WCHAR); case NCP_UTF16BE: return utf16be_to_utf32(rawdata_w, lenbytes / 2, pch32, &ch32len) * sizeof(WCHAR); case NCP_UTF8: return utf8_to_utf32(rawdata, lenbytes, pch32); default: return 0; } #else *pch32 = (ULONG)(BYTE)rawdata[0]; return 1; #endif } // // Fetch a buffer of UTF-16 text from the specified byte offset - // returns the number of characters stored in buf // // Depending on how Neatpad was compiled (UNICODE vs ANSI) this function // will always return text in the "native" format - i.e. Unicode or Ansi - // so the necessary conversions will take place here. // // TODO: make sure the CR/LF is always fetched in one go // make sure utf-16 surrogates kept together // make sure that combining chars kept together // make sure that bidirectional text kep together (will be *hard*) // // offset - BYTE offset within underlying data sequence // lenbytes - max number of bytes to process (i.e. to limit to a line) // buf - UTF16/ASCII output buffer // plen - [in] - length of buffer, [out] - number of code-units stored // // returns - number of bytes processed // ULONG TextDocument::gettext(ULONG offset, ULONG lenbytes, TCHAR *buf, ULONG *buflen) { // BYTE *rawdata = (BYTE *)(buffer + offset + m_nHeaderSize); ULONG chars_copied = 0; ULONG bytes_processed = 0; if(offset >= m_nDocLength_bytes) { *buflen = 0; return 0; } while(lenbytes > 0 && *buflen > 0) { BYTE rawdata[0x100]; size_t rawlen = min(lenbytes, 0x100); // get next block of data from the piece-table m_seq.render(offset + m_nHeaderSize, rawdata, rawlen); // convert to UTF-16 size_t tmplen = *buflen; rawlen = rawdata_to_utf16(rawdata, rawlen, buf, &tmplen); lenbytes -= rawlen; offset += rawlen; bytes_processed += rawlen; buf += tmplen; *buflen -= tmplen; chars_copied += tmplen; } *buflen = chars_copied; return bytes_processed; //ULONG remaining = lenbytes; //int charbuflen = *buflen; //while(remaining) /* { lenbytes = min(lenbytes, sizeof(rawdata)); m_seq.render(offset + m_nHeaderSize, rawdata, lenbytes); #ifdef UNICODE switch(m_nFileFormat) { // convert from ANSI->UNICODE case NCP_ASCII: return ascii_to_utf16(rawdata, lenbytes, buf, (size_t*)buflen); case NCP_UTF8: return utf8_to_utf16(rawdata, lenbytes, buf, (size_t*)buflen); // already unicode, do a straight memory copy case NCP_UTF16: return copy_utf16((WCHAR*)rawdata, lenbytes/sizeof(WCHAR), buf, (size_t*)buflen); // need to convert from big-endian to little-endian case NCP_UTF16BE: return swap_utf16((WCHAR*)rawdata, lenbytes/sizeof(WCHAR), buf, (size_t*)buflen); // error! we should *never* reach this point default: *buflen = 0; return 0; } #else switch(m_nFileFormat) { // we are already an ASCII app, so do a straight memory copy case NCP_ASCII: int len; len = min(*buflen, lenbytes); memcpy(buf, rawdata, len); *buflen = len; return len; // anything else is an error - we cannot support Unicode or multibyte // character sets with a plain ASCII app. default: *buflen = 0; return 0; } #endif // remaining -= lenbytes; // buf += lenbytes; // offset += lenbytes; }*/ } ULONG TextDocument::getdata(ULONG offset, BYTE *buf, size_t len) { //memcpy(buf, buffer + offset + m_nHeaderSize, len); m_seq.render(offset + m_nHeaderSize, buf, len); return len; } // // Initialize the line-buffer // // With Unicode a newline sequence is defined as any of the following: // // \u000A | \u000B | \u000C | \u000D | \u0085 | \u2028 | \u2029 | \u000D\u000A // bool TextDocument::init_linebuffer() { ULONG offset_bytes = 0; ULONG offset_chars = 0; ULONG linestart_bytes = 0; ULONG linestart_chars = 0; ULONG bytes_left = m_nDocLength_bytes - m_nHeaderSize; ULONG buflen = m_nDocLength_bytes - m_nHeaderSize; // allocate the line-buffer for storing each line's BYTE offset if((m_pLineBuf_byte = new ULONG[buflen+1]) == 0) return false; // allocate the line-buffer for storing each line's CHARACTER offset if((m_pLineBuf_char = new ULONG[buflen+1]) == 0) return false; m_nNumLines = 0; // loop through every byte in the file for(offset_bytes = 0; offset_bytes < buflen; ) { ULONG ch32; // get a UTF-32 character from the underlying file format. // this needs serious thought. Currently ULONG len = getchar(offset_bytes, buflen - offset_bytes, &ch32); offset_bytes += len; offset_chars += 1; if(ch32 == '\r') { // record where the line starts m_pLineBuf_byte[m_nNumLines] = linestart_bytes; m_pLineBuf_char[m_nNumLines] = linestart_chars; linestart_bytes = offset_bytes; linestart_chars = offset_chars; // look ahead to next char len = getchar(offset_bytes, buflen - offset_bytes, &ch32); offset_bytes += len; offset_chars += 1; // carriage-return / line-feed combination if(ch32 == '\n') { linestart_bytes = offset_bytes; linestart_chars = offset_chars; } m_nNumLines++; } else if(ch32 == '\n' || ch32 == '\x0b' || ch32 == '\x0c' || ch32 == 0x0085 || ch32 == 0x2029 || ch32 == 0x2028) { // record where the line starts m_pLineBuf_byte[m_nNumLines] = linestart_bytes; m_pLineBuf_char[m_nNumLines] = linestart_chars; linestart_bytes = offset_bytes; linestart_chars = offset_chars; m_nNumLines++; } // force a 'hard break' else if(offset_chars - linestart_chars > 128) { m_pLineBuf_byte[m_nNumLines] = linestart_bytes; m_pLineBuf_char[m_nNumLines] = linestart_chars; linestart_bytes = offset_bytes; linestart_chars = offset_chars; m_nNumLines++; } } if(buflen > 0) { m_pLineBuf_byte[m_nNumLines] = linestart_bytes; m_pLineBuf_char[m_nNumLines] = linestart_chars; m_nNumLines++; } m_pLineBuf_byte[m_nNumLines] = buflen; m_pLineBuf_char[m_nNumLines] = offset_chars; return true; } // // Return the number of lines // ULONG TextDocument::linecount() { return m_nNumLines; } // // Return the length of longest line // ULONG TextDocument::longestline(int tabwidth) { //ULONG i; ULONG longest = 0; ULONG xpos = 0; // char *bufptr = (char *)(buffer + m_nHeaderSize); /* for(i = 0; i < length_bytes; i++) { if(bufptr[i] == '\r') { if(bufptr[i+1] == '\n') i++; longest = max(longest, xpos); xpos = 0; } else if(bufptr[i] == '\n') { longest = max(longest, xpos); xpos = 0; } else if(bufptr[i] == '\t') { xpos += tabwidth - (xpos % tabwidth); } else { xpos ++; } } longest = max(longest, xpos);*/ return 100;//longest; } // // Return information about specified line // bool TextDocument::lineinfo_from_lineno(ULONG lineno, ULONG *lineoff_chars, ULONG *linelen_chars, ULONG *lineoff_bytes, ULONG *linelen_bytes) { if(lineno < m_nNumLines) { if(linelen_chars) *linelen_chars = m_pLineBuf_char[lineno+1] - m_pLineBuf_char[lineno]; if(lineoff_chars) *lineoff_chars = m_pLineBuf_char[lineno]; if(linelen_bytes) *linelen_bytes = m_pLineBuf_byte[lineno+1] - m_pLineBuf_byte[lineno]; if(lineoff_bytes) *lineoff_bytes = m_pLineBuf_byte[lineno]; return true; } else { return false; } } // // Perform a reverse lookup - file-offset to line number // bool TextDocument::lineinfo_from_offset(ULONG offset_chars, ULONG *lineno, ULONG *lineoff_chars, ULONG *linelen_chars, ULONG *lineoff_bytes, ULONG *linelen_bytes) { ULONG low = 0; ULONG high = m_nNumLines-1; ULONG line = 0; if(m_nNumLines == 0) { if(lineno) *lineno = 0; if(lineoff_chars) *lineoff_chars = 0; if(linelen_chars) *linelen_chars = 0; if(lineoff_bytes) *lineoff_bytes = 0; if(linelen_bytes) *linelen_bytes = 0; return false; } while(low <= high) { line = (high + low) / 2; if(offset_chars >= m_pLineBuf_char[line] && offset_chars < m_pLineBuf_char[line+1]) { break; } else if(offset_chars < m_pLineBuf_char[line]) { high = line-1; } else { low = line+1; } } if(lineno) *lineno = line; if(lineoff_bytes) *lineoff_bytes = m_pLineBuf_byte[line]; if(linelen_bytes) *linelen_bytes = m_pLineBuf_byte[line+1] - m_pLineBuf_byte[line]; if(lineoff_chars) *lineoff_chars = m_pLineBuf_char[line]; if(linelen_chars) *linelen_chars = m_pLineBuf_char[line+1] - m_pLineBuf_char[line]; return true; } int TextDocument::getformat() { return m_nFileFormat; } ULONG TextDocument::size() { return m_nDocLength_bytes; } TextIterator TextDocument::iterate(ULONG offset_chars) { ULONG off_bytes = charoffset_to_byteoffset(offset_chars); ULONG len_bytes = m_nDocLength_bytes - off_bytes; //if(!lineinfo_from_offset(offset_chars, 0, linelen, &offset_bytes, &length_bytes)) // return TextIterator(); return TextIterator(off_bytes, len_bytes, this); } // // // TextIterator TextDocument::iterate_line(ULONG lineno, ULONG *linestart, ULONG *linelen) { ULONG offset_bytes; ULONG length_bytes; if(!lineinfo_from_lineno(lineno, linestart, linelen, &offset_bytes, &length_bytes)) return TextIterator(); return TextIterator(offset_bytes, length_bytes, this); } TextIterator TextDocument::iterate_line_offset(ULONG offset_chars, ULONG *lineno, ULONG *linestart) { ULONG offset_bytes; ULONG length_bytes; if(!lineinfo_from_offset(offset_chars, lineno, linestart, 0, &offset_bytes, &length_bytes)) return TextIterator(); return TextIterator(offset_bytes, length_bytes, this); } ULONG TextDocument::lineno_from_offset(ULONG offset) { ULONG lineno = 0; lineinfo_from_offset(offset, &lineno, 0, 0, 0, 0); return lineno; } ULONG TextDocument::offset_from_lineno(ULONG lineno) { ULONG lineoff = 0; lineinfo_from_lineno(lineno, &lineoff, 0, 0, 0); return lineoff; } // // Retrieve an entire line of text // ULONG TextDocument::getline(ULONG nLineNo, TCHAR *buf, ULONG buflen, ULONG *off_chars) { ULONG offset_bytes; ULONG length_bytes; ULONG offset_chars; ULONG length_chars; if(!lineinfo_from_lineno(nLineNo, &offset_chars, &length_chars, &offset_bytes, &length_bytes)) { *off_chars = 0; return 0; } gettext(offset_bytes, length_bytes, buf, &buflen); *off_chars = offset_chars; return buflen; } // // Convert the RAW buffer in underlying file-format to UTF-16 // // // utf16len - [in/out] on input holds size of utf16str buffer, // on output holds number of utf16 characters stored // // returns bytes processed from rawdata // size_t TextDocument::rawdata_to_utf16(BYTE *rawdata, size_t rawlen, TCHAR *utf16str, size_t *utf16len) { switch(m_nFileFormat) { // convert from ANSI->UNICODE case NCP_ASCII: return ascii_to_utf16(rawdata, rawlen, (UTF16 *)utf16str, utf16len); case NCP_UTF8: return utf8_to_utf16(rawdata, rawlen, (UTF16 *)utf16str, utf16len); // already unicode, do a straight memory copy case NCP_UTF16: rawlen /= sizeof(TCHAR); return copy_utf16((UTF16 *)rawdata, rawlen, (UTF16 *)utf16str, utf16len) * sizeof(TCHAR); // need to convert from big-endian to little-endian case NCP_UTF16BE: rawlen /= sizeof(TCHAR); return swap_utf16((UTF16 *)rawdata, rawlen, (UTF16 *)utf16str, utf16len) * sizeof(TCHAR); // error! we should *never* reach this point default: *utf16len = 0; return 0; } } // // Converts specified UTF16 string to the underlying RAW format of the text-document // (i.e. UTF-16 -> UTF-8 // UTF-16 -> UTF-32 etc) // // returns number of WCHARs processed from utf16str // size_t TextDocument::utf16_to_rawdata(TCHAR *utf16str, size_t utf16len, BYTE *rawdata, size_t *rawlen) { switch(m_nFileFormat) { // convert from UTF16 -> ASCII case NCP_ASCII: return utf16_to_ascii((UTF16 *)utf16str, utf16len, rawdata, rawlen); // convert from UTF16 -> UTF8 case NCP_UTF8: return utf16_to_utf8((UTF16 *)utf16str, utf16len, rawdata, rawlen); // already unicode, do a straight memory copy case NCP_UTF16: *rawlen /= sizeof(TCHAR); utf16len = copy_utf16((UTF16 *)utf16str, utf16len, (UTF16 *)rawdata, rawlen); *rawlen *= sizeof(TCHAR); return utf16len; // need to convert from big-endian to little-endian case NCP_UTF16BE: *rawlen /= sizeof(TCHAR); utf16len = swap_utf16((UTF16 *)utf16str, utf16len, (UTF16 *)rawdata, rawlen); *rawlen *= sizeof(TCHAR); return utf16len; // error! we should *never* reach this point default: *rawlen = 0; return 0; } } // // Insert UTF-16 text at specified BYTE offset // // returns number of BYTEs stored // ULONG TextDocument::insert_raw(ULONG offset_bytes, TCHAR *text, ULONG length) { BYTE buf[0x100]; ULONG buflen; ULONG copied; ULONG rawlen = 0; ULONG offset = offset_bytes+ m_nHeaderSize; while(length) { buflen = 0x100; copied = utf16_to_rawdata(text, length, buf, (size_t *)&buflen); // do the piece-table insertion! if(!m_seq.insert(offset, buf, buflen)) break; text += copied; length -= copied; rawlen += buflen; offset += buflen; } m_nDocLength_bytes = m_seq.size(); return rawlen; } ULONG TextDocument::replace_raw(ULONG offset_bytes, TCHAR *text, ULONG length, ULONG erase_chars) { BYTE buf[0x100]; ULONG buflen; ULONG copied; ULONG rawlen = 0; ULONG offset = offset_bytes + m_nHeaderSize; ULONG erase_bytes = count_chars(offset_bytes, erase_chars); while(length) { buflen = 0x100; copied = utf16_to_rawdata(text, length, buf, (size_t *)&buflen); // do the piece-table replacement! if(!m_seq.replace(offset, buf, buflen, erase_bytes)) break; text += copied; length -= copied; rawlen += buflen; offset += buflen; erase_bytes = 0; } m_nDocLength_bytes = m_seq.size(); return rawlen; } // // Erase is a little different. Need to work out how many // bytes the specified number of UTF16 characters takes up // ULONG TextDocument::erase_raw(ULONG offset_bytes, ULONG length) { /*TCHAR buf[0x100]; ULONG buflen; ULONG bytes; ULONG erase_bytes = 0; ULONG erase_offset = offset_bytes; while(length) { buflen = min(0x100, length); bytes = gettext(offset_bytes, 0x100, buf, &buflen); erase_bytes += bytes; offset_bytes += bytes; length -= buflen; } // do the piece-table deletion! if(m_seq.erase(erase_offset + m_nHeaderSize, erase_bytes)) { m_nDocLength_bytes = m_seq.size(); return length; }*/ ULONG erase_bytes = count_chars(offset_bytes, length); if(m_seq.erase(offset_bytes + m_nHeaderSize, erase_bytes)) { m_nDocLength_bytes = m_seq.size(); return length; } return 0; } // // return number of bytes comprising 'length_chars' characters // in the underlying raw file // ULONG TextDocument::count_chars(ULONG offset_bytes, ULONG length_chars) { switch(m_nFileFormat) { case NCP_ASCII: return length_chars; case NCP_UTF16: case NCP_UTF16BE: return length_chars * sizeof(WCHAR); default: break; } ULONG offset_start = offset_bytes; while(length_chars && offset_bytes < m_nDocLength_bytes) { TCHAR buf[0x100]; ULONG charlen = min(length_chars, 0x100); ULONG bytelen; bytelen = gettext(offset_bytes, m_nDocLength_bytes - offset_bytes, buf, &charlen); length_chars -= charlen; offset_bytes += bytelen; } return offset_bytes - offset_start; } ULONG TextDocument::byteoffset_to_charoffset(ULONG offset_bytes) { switch(m_nFileFormat) { case NCP_ASCII: return offset_bytes; case NCP_UTF16: case NCP_UTF16BE: return offset_bytes / sizeof(WCHAR); case NCP_UTF8: case NCP_UTF32: case NCP_UTF32BE: // bug bug! need to implement this. default: break; } return 0; } ULONG TextDocument::charoffset_to_byteoffset(ULONG offset_chars) { switch(m_nFileFormat) { case NCP_ASCII: return offset_chars; case NCP_UTF16: case NCP_UTF16BE: return offset_chars * sizeof(WCHAR); case NCP_UTF8: case NCP_UTF32: case NCP_UTF32BE: default: break; } ULONG lineoff_chars; ULONG lineoff_bytes; if(lineinfo_from_offset(offset_chars, 0, &lineoff_chars, 0, &lineoff_bytes, 0)) { return count_chars(lineoff_bytes, offset_chars - lineoff_chars) + lineoff_bytes; } else { return 0; } } // // Insert text at specified character-offset // ULONG TextDocument::insert_text(ULONG offset_chars, TCHAR *text, ULONG length) { ULONG offset_bytes = charoffset_to_byteoffset(offset_chars); return insert_raw(offset_bytes, text, length); } // // Overwrite text at specified character-offset // ULONG TextDocument::replace_text(ULONG offset_chars, TCHAR *text, ULONG length, ULONG erase_len) { ULONG offset_bytes = charoffset_to_byteoffset(offset_chars); return replace_raw(offset_bytes, text, length, erase_len); } // // Erase text at specified character-offset // ULONG TextDocument::erase_text(ULONG offset_chars, ULONG length) { ULONG offset_bytes = charoffset_to_byteoffset(offset_chars); return erase_raw(offset_bytes, length); } bool TextDocument::Undo(ULONG *offset_start, ULONG *offset_end) { ULONG start, length; if(!m_seq.undo()) return false; start = m_seq.event_index() - m_nHeaderSize; length = m_seq.event_length(); *offset_start = byteoffset_to_charoffset(start); *offset_end = byteoffset_to_charoffset(start+length); m_nDocLength_bytes = m_seq.size(); return true; } bool TextDocument::Redo(ULONG *offset_start, ULONG *offset_end) { ULONG start, length; if(!m_seq.redo()) return false; start = m_seq.event_index() - m_nHeaderSize; length = m_seq.event_length(); *offset_start = byteoffset_to_charoffset(start); *offset_end = byteoffset_to_charoffset(start+length); m_nDocLength_bytes = m_seq.size(); return true; }
07-02
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/Administrator/.m2/repository/org/slf4j/slf4j-log4j12/1.7.30/slf4j-log4j12-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/Administrator/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.10.0/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/Administrator/.m2/repository/org/slf4j/slf4j-simple/1.7.30/slf4j-simple-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] 2025-11-24 09:27:04,150 WARN [org.apache.hadoop.metrics2.impl.MetricsConfig] - Cannot locate configuration: tried hadoop-metrics2-jobtracker.properties,hadoop-metrics2.properties 2025-11-24 09:27:04,189 INFO [org.apache.hadoop.metrics2.impl.MetricsSystemImpl] - Scheduled Metric snapshot period at 10 second(s). 2025-11-24 09:27:04,189 INFO [org.apache.hadoop.metrics2.impl.MetricsSystemImpl] - JobTracker metrics system started 2025-11-24 09:27:04,386 WARN [org.apache.hadoop.mapreduce.JobResourceUploader] - Hadoop command-line option parsing not performed. Implement the Tool interface and execute your application with ToolRunner to remedy this. 2025-11-24 09:27:04,395 WARN [org.apache.hadoop.mapreduce.JobResourceUploader] - No job jar file set. User classes may not be found. See Job or Job#setJar(String). 2025-11-24 09:27:04,416 INFO [org.apache.hadoop.mapreduce.lib.input.FileInputFormat] - Total input files to process : 1 2025-11-24 09:27:04,433 INFO [org.apache.hadoop.mapreduce.JobSubmitter] - number of splits:1 2025-11-24 09:27:04,485 INFO [org.apache.hadoop.mapreduce.JobSubmitter] - Submitting tokens for job: job_local2106793956_0001 2025-11-24 09:27:04,486 INFO [org.apache.hadoop.mapreduce.JobSubmitter] - Executing with tokens: [] 2025-11-24 09:27:04,554 INFO [org.apache.hadoop.mapreduce.Job] - The url to track the job: http://localhost:8080/ 2025-11-24 09:27:04,555 INFO [org.apache.hadoop.mapreduce.Job] - Running job: job_local2106793956_0001 2025-11-24 09:27:04,555 INFO [org.apache.hadoop.mapred.LocalJobRunner] - OutputCommitter set in config null 2025-11-24 09:27:04,559 INFO [org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter] - File Output Committer Algorithm version is 2 2025-11-24 09:27:04,559 INFO [org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter] - FileOutputCommitter skip cleanup _temporary folders under output directory:false, ignore cleanup failures: false 2025-11-24 09:27:04,559 INFO [org.apache.hadoop.mapred.LocalJobRunner] - OutputCommitter is org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter 2025-11-24 09:27:04,589 INFO [org.apache.hadoop.mapred.LocalJobRunner] - Waiting for map tasks 2025-11-24 09:27:04,589 INFO [org.apache.hadoop.mapred.LocalJobRunner] - Starting task: attempt_local2106793956_0001_m_000000_0 2025-11-24 09:27:04,601 INFO [org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter] - File Output Committer Algorithm version is 2 2025-11-24 09:27:04,601 INFO [org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter] - FileOutputCommitter skip cleanup _temporary folders under output directory:false, ignore cleanup failures: false 2025-11-24 09:27:04,607 INFO [org.apache.hadoop.yarn.util.ProcfsBasedProcessTree] - ProcfsBasedProcessTree currently is supported only on Linux. 2025-11-24 09:27:04,631 INFO [org.apache.hadoop.mapred.Task] - Using ResourceCalculatorProcessTree : org.apache.hadoop.yarn.util.WindowsBasedProcessTree@1439d592 2025-11-24 09:27:04,634 INFO [org.apache.hadoop.mapred.MapTask] - Processing split: file:/D:/dgh/java/Hadoop/input/subject_score.csv:0+80578 2025-11-24 09:27:04,673 INFO [org.apache.hadoop.mapred.MapTask] - (EQUATOR) 0 kvi 26214396(104857584) 2025-11-24 09:27:04,673 INFO [org.apache.hadoop.mapred.MapTask] - mapreduce.task.io.sort.mb: 100 2025-11-24 09:27:04,673 INFO [org.apache.hadoop.mapred.MapTask] - soft limit at 83886080 2025-11-24 09:27:04,673 INFO [org.apache.hadoop.mapred.MapTask] - bufstart = 0; bufvoid = 104857600 2025-11-24 09:27:04,673 INFO [org.apache.hadoop.mapred.MapTask] - kvstart = 26214396; length = 6553600 2025-11-24 09:27:04,675 INFO [org.apache.hadoop.mapred.MapTask] - Map output collector class = org.apache.hadoop.mapred.MapTask$MapOutputBuffer 2025-11-24 09:27:04,709 INFO [org.apache.hadoop.mapred.LocalJobRunner] - 2025-11-24 09:27:04,709 INFO [org.apache.hadoop.mapred.MapTask] - Starting flush of map output 2025-11-24 09:27:04,709 INFO [org.apache.hadoop.mapred.MapTask] - Spilling map output 2025-11-24 09:27:04,709 INFO [org.apache.hadoop.mapred.MapTask] - bufstart = 0; bufend = 42108; bufvoid = 104857600 2025-11-24 09:27:04,709 INFO [org.apache.hadoop.mapred.MapTask] - kvstart = 26214396(104857584); kvend = 26199088(104796352); length = 15309/6553600 2025-11-24 09:27:04,732 INFO [org.apache.hadoop.mapred.MapTask] - Finished spill 0 2025-11-24 09:27:04,744 INFO [org.apache.hadoop.mapred.Task] - Task:attempt_local2106793956_0001_m_000000_0 is done. And is in the process of committing 2025-11-24 09:27:04,745 INFO [org.apache.hadoop.mapred.LocalJobRunner] - map 2025-11-24 09:27:04,745 INFO [org.apache.hadoop.mapred.Task] - Task 'attempt_local2106793956_0001_m_000000_0' done. 2025-11-24 09:27:04,749 INFO [org.apache.hadoop.mapred.Task] - Final Counters for attempt_local2106793956_0001_m_000000_0: Counters: 17 File System Counters FILE: Number of bytes read=80748 FILE: Number of bytes written=446408 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 Map-Reduce Framework Map input records=3828 Map output records=3828 Map output bytes=42108 Map output materialized bytes=49770 Input split bytes=113 Combine input records=0 Spilled Records=3828 Failed Shuffles=0 Merged Map outputs=0 GC time elapsed (ms)=4 Total committed heap usage (bytes)=265814016 File Input Format Counters Bytes Read=80578 2025-11-24 09:27:04,749 INFO [org.apache.hadoop.mapred.LocalJobRunner] - Finishing task: attempt_local2106793956_0001_m_000000_0 2025-11-24 09:27:04,749 INFO [org.apache.hadoop.mapred.LocalJobRunner] - map task executor complete. 2025-11-24 09:27:04,750 INFO [org.apache.hadoop.mapred.LocalJobRunner] - Waiting for reduce tasks 2025-11-24 09:27:04,751 INFO [org.apache.hadoop.mapred.LocalJobRunner] - Starting task: attempt_local2106793956_0001_r_000000_0 2025-11-24 09:27:04,754 INFO [org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter] - File Output Committer Algorithm version is 2 2025-11-24 09:27:04,754 INFO [org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter] - FileOutputCommitter skip cleanup _temporary folders under output directory:false, ignore cleanup failures: false 2025-11-24 09:27:04,754 INFO [org.apache.hadoop.yarn.util.ProcfsBasedProcessTree] - ProcfsBasedProcessTree currently is supported only on Linux. 2025-11-24 09:27:04,776 INFO [org.apache.hadoop.mapred.Task] - Using ResourceCalculatorProcessTree : org.apache.hadoop.yarn.util.WindowsBasedProcessTree@7b215062 2025-11-24 09:27:04,778 INFO [org.apache.hadoop.mapred.ReduceTask] - Using ShuffleConsumerPlugin: org.apache.hadoop.mapreduce.task.reduce.Shuffle@5bb9ff0f 2025-11-24 09:27:04,779 WARN [org.apache.hadoop.metrics2.impl.MetricsSystemImpl] - JobTracker metrics system already initialized! 2025-11-24 09:27:04,785 INFO [org.apache.hadoop.mapreduce.task.reduce.MergeManagerImpl] - MergerManager: memoryLimit=1305057664, maxSingleShuffleLimit=326264416, mergeThreshold=861338112, ioSortFactor=10, memToMemMergeOutputsThreshold=10 2025-11-24 09:27:04,786 INFO [org.apache.hadoop.mapreduce.task.reduce.EventFetcher] - attempt_local2106793956_0001_r_000000_0 Thread started: EventFetcher for fetching Map Completion Events 2025-11-24 09:27:04,800 INFO [org.apache.hadoop.mapreduce.task.reduce.LocalFetcher] - localfetcher#1 about to shuffle output of map attempt_local2106793956_0001_m_000000_0 decomp: 49766 len: 49770 to MEMORY 2025-11-24 09:27:04,803 INFO [org.apache.hadoop.mapreduce.task.reduce.InMemoryMapOutput] - Read 49766 bytes from map-output for attempt_local2106793956_0001_m_000000_0 2025-11-24 09:27:04,803 INFO [org.apache.hadoop.mapreduce.task.reduce.MergeManagerImpl] - closeInMemoryFile -> map-output of size: 49766, inMemoryMapOutputs.size() -> 1, commitMemory -> 0, usedMemory ->49766 2025-11-24 09:27:04,804 INFO [org.apache.hadoop.mapreduce.task.reduce.EventFetcher] - EventFetcher is interrupted.. Returning 2025-11-24 09:27:04,804 INFO [org.apache.hadoop.mapred.LocalJobRunner] - 1 / 1 copied. 2025-11-24 09:27:04,804 INFO [org.apache.hadoop.mapreduce.task.reduce.MergeManagerImpl] - finalMerge called with 1 in-memory map-outputs and 0 on-disk map-outputs 2025-11-24 09:27:04,811 INFO [org.apache.hadoop.mapred.Merger] - Merging 1 sorted segments 2025-11-24 09:27:04,811 INFO [org.apache.hadoop.mapred.Merger] - Down to the last merge-pass, with 1 segments left of total size: 49757 bytes 2025-11-24 09:27:04,817 INFO [org.apache.hadoop.mapreduce.task.reduce.MergeManagerImpl] - Merged 1 segments, 49766 bytes to disk to satisfy reduce memory limit 2025-11-24 09:27:04,818 INFO [org.apache.hadoop.mapreduce.task.reduce.MergeManagerImpl] - Merging 1 files, 49770 bytes from disk 2025-11-24 09:27:04,818 INFO [org.apache.hadoop.mapreduce.task.reduce.MergeManagerImpl] - Merging 0 segments, 0 bytes from memory into reduce 2025-11-24 09:27:04,818 INFO [org.apache.hadoop.mapred.Merger] - Merging 1 sorted segments 2025-11-24 09:27:04,819 INFO [org.apache.hadoop.mapred.Merger] - Down to the last merge-pass, with 1 segments left of total size: 49757 bytes 2025-11-24 09:27:04,819 INFO [org.apache.hadoop.mapred.LocalJobRunner] - 1 / 1 copied. 2025-11-24 09:27:04,822 INFO [org.apache.hadoop.conf.Configuration.deprecation] - mapred.skip.on is deprecated. Instead, use mapreduce.job.skiprecords 2025-11-24 09:27:04,835 INFO [org.apache.hadoop.mapred.Task] - Task:attempt_local2106793956_0001_r_000000_0 is done. And is in the process of committing 2025-11-24 09:27:04,836 INFO [org.apache.hadoop.mapred.LocalJobRunner] - 1 / 1 copied. 2025-11-24 09:27:04,836 INFO [org.apache.hadoop.mapred.Task] - Task attempt_local2106793956_0001_r_000000_0 is allowed to commit now 2025-11-24 09:27:04,839 INFO [org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter] - Saved output of task 'attempt_local2106793956_0001_r_000000_0' to file:/D:/dgh/java/Hadoop/output 2025-11-24 09:27:04,839 INFO [org.apache.hadoop.mapred.LocalJobRunner] - reduce > reduce 2025-11-24 09:27:04,839 INFO [org.apache.hadoop.mapred.Task] - Task 'attempt_local2106793956_0001_r_000000_0' done. 2025-11-24 09:27:04,840 INFO [org.apache.hadoop.mapred.Task] - Final Counters for attempt_local2106793956_0001_r_000000_0: Counters: 24 File System Counters FILE: Number of bytes read=180320 FILE: Number of bytes written=496250 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 Map-Reduce Framework Combine input records=0 Combine output records=0 Reduce input groups=6 Reduce shuffle bytes=49770 Reduce input records=3828 Reduce output records=6 Spilled Records=3828 Shuffled Maps =1 Failed Shuffles=0 Merged Map outputs=1 GC time elapsed (ms)=0 Total committed heap usage (bytes)=265814016 Shuffle Errors BAD_ID=0 CONNECTION=0 IO_ERROR=0 WRONG_LENGTH=0 WRONG_MAP=0 WRONG_REDUCE=0 File Output Format Counters Bytes Written=72 2025-11-24 09:27:04,840 INFO [org.apache.hadoop.mapred.LocalJobRunner] - Finishing task: attempt_local2106793956_0001_r_000000_0 2025-11-24 09:27:04,840 INFO [org.apache.hadoop.mapred.LocalJobRunner] - reduce task executor complete. 2025-11-24 09:27:05,564 INFO [org.apache.hadoop.mapreduce.Job] - Job job_local2106793956_0001 running in uber mode : false 2025-11-24 09:27:05,565 INFO [org.apache.hadoop.mapreduce.Job] - map 100% reduce 100% 2025-11-24 09:27:05,566 INFO [org.apache.hadoop.mapreduce.Job] - Job job_local2106793956_0001 completed successfully 2025-11-24 09:27:05,569 INFO [org.apache.hadoop.mapreduce.Job] - Counters: 30 File System Counters FILE: Number of bytes read=261068 FILE: Number of bytes written=942658 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 Map-Reduce Framework Map input records=3828 Map output records=3828 Map output bytes=42108 Map output materialized bytes=49770 Input split bytes=113 Combine input records=0 Combine output records=0 Reduce input groups=6 Reduce shuffle bytes=49770 Reduce input records=3828 Reduce output records=6 Spilled Records=7656 Shuffled Maps =1 Failed Shuffles=0 Merged Map outputs=1 GC time elapsed (ms)=4 Total committed heap usage (bytes)=531628032 Shuffle Errors BAD_ID=0 CONNECTION=0 IO_ERROR=0 WRONG_LENGTH=0 WRONG_MAP=0 WRONG_REDUCE=0 File Input Format Counters Bytes Read=80578 File Output Format Counters Bytes Written=72 Process finished with exit code 0 运行以后是这样的
11-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值