- 浏览: 162872 次
- 性别:
- 来自: 北京
-
文章分类
最新评论
-
yzd_java:
你的uploadFile.html怎么没有贴出来
uploadify 3.2.1+spring mvc上传文件 -
u013107014:
不能多选,不能阅览,搞J8
uploadify 3.2.1+spring mvc上传文件 -
u013107014:
什么JB鬼?
uploadify 3.2.1+spring mvc上传文件 -
11104078:
uploadify 3.2.1+spring mvc上传文件 -
xujun738:
楼主,为什么我按照你说的做,只生成了一级,点展开树结点的时候就 ...
zk生成多级树
ldap http://www.360doc.com/content/08/0220/09/48984_1055997.shtml
public class BookPageFactory {
private File book_file = null;
private MappedByteBuffer m_mbBuf = null;
private int m_mbBufLen = 0;
private int m_mbBufBegin = 0;
private int m_mbBufEnd = 0;
private String m_textCode = "GBK";
private Bitmap m_book_bg = null;
private int mWidth;
private int mHeight;
private Vector<String> m_lines = new Vector<String>();
private int m_fontSize = 20;
private int m_textColor = Color.BLACK;
private int m_backColor = 0xffff9e85;
private int marginWidth = 15;
private int marginHeight = 20;
private int mLineCount;
private float mVisibleHeight;
private float mVisibleWidth;
private boolean m_isfirstPage,m_islastPage;
// private int m_nLineSpaceing = 5;
private Paint mPaint;
public BookPageFactory(int w, int h) {
// TODO Auto-generated constructor stub
mWidth = w;
mHeight = h;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setTextAlign(Align.LEFT);
mPaint.setTextSize(m_fontSize);
mPaint.setColor(m_textColor);
mVisibleWidth = mWidth - marginWidth * 2;
mVisibleHeight = mHeight - marginHeight * 2;
mLineCount = (int) (mVisibleHeight / m_fontSize);
}
/**
* 读取本地图书
*
* @param filePath 文件路径
* @throws IOException
*/
public void openbook(String filePath) throws IOException {
book_file = new File(filePath);
String encoding = FileLocalCache.getTextCode(filePath);
m_textCode = FileLocalCache.coverEncoding(encoding);
long lLen = book_file.length();
m_mbBufLen = (int) lLen;
m_mbBuf = new RandomAccessFile(book_file, "r").getChannel().map(
FileChannel.MapMode.READ_ONLY, 0, lLen);
}
protected byte[] readParagraphBack(int nFromPos) {
int nEnd = nFromPos;
int i;
byte b0, b1;
if (m_textCode.equals("UTF-16LE")) {
i = nEnd - 2;
while (i > 0) {
b0 = m_mbBuf.get(i);
b1 = m_mbBuf.get(i + 1);
if (b0 == 0x0a && b1 == 0x00 && i != nEnd - 2) {
i += 2;
break;
}
i--;
}
} else if (m_textCode.equals("UTF-16BE")) {
i = nEnd - 2;
while (i > 0) {
b0 = m_mbBuf.get(i);
b1 = m_mbBuf.get(i + 1);
if (b0 == 0x00 && b1 == 0x0a && i != nEnd - 2) {
i += 2;
break;
}
i--;
}
} else {
i = nEnd - 1;
while (i > 0) {
b0 = m_mbBuf.get(i);
if (b0 == 0x0a && i != nEnd - 1) {
i++;
break;
}
i--;
}
}
if (i < 0)
i = 0;
int nParaSize = nEnd - i;
int j;
byte[] buf = new byte[nParaSize];
for (j = 0; j < nParaSize; j++) {
buf[j] = m_mbBuf.get(i + j);
}
return buf;
}
protected byte[] readParagraphForward(int nFromPos) {
int nStart = nFromPos;
int i = nStart;
byte b0, b1;
if (m_textCode.equals("UTF-16LE")) {
while (i < m_mbBufLen - 1) {
b0 = m_mbBuf.get(i++);
b1 = m_mbBuf.get(i++);
if (b0 == 0x0a && b1 == 0x00) {
break;
}
}
} else if (m_textCode.equals("UTF-16BE")) {
while (i < m_mbBufLen - 1) {
b0 = m_mbBuf.get(i++);
b1 = m_mbBuf.get(i++);
if (b0 == 0x00 && b1 == 0x0a) {
break;
}
}
} else {
while (i < m_mbBufLen) {
b0 = m_mbBuf.get(i++);
if (b0 == 0x0a) {
break;
}
}
}
int nParaSize = i - nStart;
byte[] buf = new byte[nParaSize];
for (i = 0; i < nParaSize; i++) {
buf[i] = m_mbBuf.get(nFromPos + i);
}
return buf;
}
/**
* next page
*/
protected Vector<String> pageDown() {
String strParagraph = "";
Vector<String> lines = new Vector<String>();
while (lines.size() < mLineCount && m_mbBufEnd < m_mbBufLen) {
byte[] paraBuf = readParagraphForward(m_mbBufEnd);
m_mbBufEnd += paraBuf.length;
try {
strParagraph = new String(paraBuf, m_textCode);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String strReturn = "";
if (strParagraph.indexOf("\r\n") != -1) {
strReturn = "\r\n";
strParagraph = strParagraph.replaceAll("\r\n", "");
} else if (strParagraph.indexOf("\n") != -1) {
strReturn = "\n";
strParagraph = strParagraph.replaceAll("\n", "");
}
if (strParagraph.length() == 0) {
lines.add(strParagraph);
}
while (strParagraph.length() > 0) {
int nSize = mPaint.breakText(strParagraph, true, mVisibleWidth,
null);
lines.add(strParagraph.substring(0, nSize));
strParagraph = strParagraph.substring(nSize);
if (lines.size() >= mLineCount) {
break;
}
}
if (strParagraph.length() != 0) {
try {
m_mbBufEnd -= (strParagraph + strReturn)
.getBytes(m_textCode).length;
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return lines;
}
protected void pageUp() {
if (m_mbBufBegin < 0)
m_mbBufBegin = 0;
Vector<String> lines = new Vector<String>();
String strParagraph = "";
while (lines.size() < mLineCount && m_mbBufBegin > 0) {
Vector<String> paraLines = new Vector<String>();
byte[] paraBuf = readParagraphBack(m_mbBufBegin);
m_mbBufBegin -= paraBuf.length;
try {
strParagraph = new String(paraBuf, m_textCode);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
strParagraph = strParagraph.replaceAll("\r\n", "");
strParagraph = strParagraph.replaceAll("\n", "");
if (strParagraph.length() == 0) {
paraLines.add(strParagraph);
}
while (strParagraph.length() > 0) {
int nSize = mPaint.breakText(strParagraph, true, mVisibleWidth,
null);
paraLines.add(strParagraph.substring(0, nSize));
strParagraph = strParagraph.substring(nSize);
}
lines.addAll(0, paraLines);
}
while (lines.size() > mLineCount) {
try {
m_mbBufBegin += lines.get(0).getBytes(m_textCode).length;
lines.remove(0);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
m_mbBufEnd = m_mbBufBegin;
return;
}
public void prePage() throws IOException {
if (m_mbBufBegin <= 0) {
m_mbBufBegin = 0;
m_isfirstPage=true;
return;
}else m_isfirstPage=false;
m_lines.clear();
pageUp();
m_lines = pageDown();
}
public void nextPage() throws IOException {
if (m_mbBufEnd >= m_mbBufLen) {
m_islastPage=true;
return;
}else m_islastPage=false;
m_lines.clear();
m_mbBufBegin = m_mbBufEnd;
m_lines = pageDown();
}
public void onDraw(Canvas c) {
if (m_lines.size() == 0)
m_lines = pageDown();
if (m_lines.size() > 0) {
if (m_book_bg == null)
c.drawColor(m_backColor);
else
c.drawBitmap(m_book_bg, 0, 0, null);
int y = marginHeight;
for (String strLine : m_lines) {
y += m_fontSize;
c.drawText(strLine, marginWidth, y, mPaint);
}
}
float fPercent = (float) (m_mbBufBegin * 1.0 / m_mbBufLen);
DecimalFormat df = new DecimalFormat("#0.0");
String strPercent = df.format(fPercent * 100) + "%";
int nPercentWidth = (int) mPaint.measureText("999.9%") + 1;
c.drawText(strPercent, mWidth - nPercentWidth, mHeight - 5, mPaint);
}
public void setBgBitmap(Bitmap BG) {
m_book_bg = BG;
}
public boolean isfirstPage() {
return m_isfirstPage;
}
public boolean islastPage() {
return m_islastPage;
}
public void setTextCode(String textCode){
this.m_textCode = textCode;
}
}
public class BookPageFactory {
private File book_file = null;
private MappedByteBuffer m_mbBuf = null;
private int m_mbBufLen = 0;
private int m_mbBufBegin = 0;
private int m_mbBufEnd = 0;
private String m_textCode = "GBK";
private Bitmap m_book_bg = null;
private int mWidth;
private int mHeight;
private Vector<String> m_lines = new Vector<String>();
private int m_fontSize = 20;
private int m_textColor = Color.BLACK;
private int m_backColor = 0xffff9e85;
private int marginWidth = 15;
private int marginHeight = 20;
private int mLineCount;
private float mVisibleHeight;
private float mVisibleWidth;
private boolean m_isfirstPage,m_islastPage;
// private int m_nLineSpaceing = 5;
private Paint mPaint;
public BookPageFactory(int w, int h) {
// TODO Auto-generated constructor stub
mWidth = w;
mHeight = h;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setTextAlign(Align.LEFT);
mPaint.setTextSize(m_fontSize);
mPaint.setColor(m_textColor);
mVisibleWidth = mWidth - marginWidth * 2;
mVisibleHeight = mHeight - marginHeight * 2;
mLineCount = (int) (mVisibleHeight / m_fontSize);
}
/**
* 读取本地图书
*
* @param filePath 文件路径
* @throws IOException
*/
public void openbook(String filePath) throws IOException {
book_file = new File(filePath);
String encoding = FileLocalCache.getTextCode(filePath);
m_textCode = FileLocalCache.coverEncoding(encoding);
long lLen = book_file.length();
m_mbBufLen = (int) lLen;
m_mbBuf = new RandomAccessFile(book_file, "r").getChannel().map(
FileChannel.MapMode.READ_ONLY, 0, lLen);
}
protected byte[] readParagraphBack(int nFromPos) {
int nEnd = nFromPos;
int i;
byte b0, b1;
if (m_textCode.equals("UTF-16LE")) {
i = nEnd - 2;
while (i > 0) {
b0 = m_mbBuf.get(i);
b1 = m_mbBuf.get(i + 1);
if (b0 == 0x0a && b1 == 0x00 && i != nEnd - 2) {
i += 2;
break;
}
i--;
}
} else if (m_textCode.equals("UTF-16BE")) {
i = nEnd - 2;
while (i > 0) {
b0 = m_mbBuf.get(i);
b1 = m_mbBuf.get(i + 1);
if (b0 == 0x00 && b1 == 0x0a && i != nEnd - 2) {
i += 2;
break;
}
i--;
}
} else {
i = nEnd - 1;
while (i > 0) {
b0 = m_mbBuf.get(i);
if (b0 == 0x0a && i != nEnd - 1) {
i++;
break;
}
i--;
}
}
if (i < 0)
i = 0;
int nParaSize = nEnd - i;
int j;
byte[] buf = new byte[nParaSize];
for (j = 0; j < nParaSize; j++) {
buf[j] = m_mbBuf.get(i + j);
}
return buf;
}
protected byte[] readParagraphForward(int nFromPos) {
int nStart = nFromPos;
int i = nStart;
byte b0, b1;
if (m_textCode.equals("UTF-16LE")) {
while (i < m_mbBufLen - 1) {
b0 = m_mbBuf.get(i++);
b1 = m_mbBuf.get(i++);
if (b0 == 0x0a && b1 == 0x00) {
break;
}
}
} else if (m_textCode.equals("UTF-16BE")) {
while (i < m_mbBufLen - 1) {
b0 = m_mbBuf.get(i++);
b1 = m_mbBuf.get(i++);
if (b0 == 0x00 && b1 == 0x0a) {
break;
}
}
} else {
while (i < m_mbBufLen) {
b0 = m_mbBuf.get(i++);
if (b0 == 0x0a) {
break;
}
}
}
int nParaSize = i - nStart;
byte[] buf = new byte[nParaSize];
for (i = 0; i < nParaSize; i++) {
buf[i] = m_mbBuf.get(nFromPos + i);
}
return buf;
}
/**
* next page
*/
protected Vector<String> pageDown() {
String strParagraph = "";
Vector<String> lines = new Vector<String>();
while (lines.size() < mLineCount && m_mbBufEnd < m_mbBufLen) {
byte[] paraBuf = readParagraphForward(m_mbBufEnd);
m_mbBufEnd += paraBuf.length;
try {
strParagraph = new String(paraBuf, m_textCode);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String strReturn = "";
if (strParagraph.indexOf("\r\n") != -1) {
strReturn = "\r\n";
strParagraph = strParagraph.replaceAll("\r\n", "");
} else if (strParagraph.indexOf("\n") != -1) {
strReturn = "\n";
strParagraph = strParagraph.replaceAll("\n", "");
}
if (strParagraph.length() == 0) {
lines.add(strParagraph);
}
while (strParagraph.length() > 0) {
int nSize = mPaint.breakText(strParagraph, true, mVisibleWidth,
null);
lines.add(strParagraph.substring(0, nSize));
strParagraph = strParagraph.substring(nSize);
if (lines.size() >= mLineCount) {
break;
}
}
if (strParagraph.length() != 0) {
try {
m_mbBufEnd -= (strParagraph + strReturn)
.getBytes(m_textCode).length;
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return lines;
}
protected void pageUp() {
if (m_mbBufBegin < 0)
m_mbBufBegin = 0;
Vector<String> lines = new Vector<String>();
String strParagraph = "";
while (lines.size() < mLineCount && m_mbBufBegin > 0) {
Vector<String> paraLines = new Vector<String>();
byte[] paraBuf = readParagraphBack(m_mbBufBegin);
m_mbBufBegin -= paraBuf.length;
try {
strParagraph = new String(paraBuf, m_textCode);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
strParagraph = strParagraph.replaceAll("\r\n", "");
strParagraph = strParagraph.replaceAll("\n", "");
if (strParagraph.length() == 0) {
paraLines.add(strParagraph);
}
while (strParagraph.length() > 0) {
int nSize = mPaint.breakText(strParagraph, true, mVisibleWidth,
null);
paraLines.add(strParagraph.substring(0, nSize));
strParagraph = strParagraph.substring(nSize);
}
lines.addAll(0, paraLines);
}
while (lines.size() > mLineCount) {
try {
m_mbBufBegin += lines.get(0).getBytes(m_textCode).length;
lines.remove(0);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
m_mbBufEnd = m_mbBufBegin;
return;
}
public void prePage() throws IOException {
if (m_mbBufBegin <= 0) {
m_mbBufBegin = 0;
m_isfirstPage=true;
return;
}else m_isfirstPage=false;
m_lines.clear();
pageUp();
m_lines = pageDown();
}
public void nextPage() throws IOException {
if (m_mbBufEnd >= m_mbBufLen) {
m_islastPage=true;
return;
}else m_islastPage=false;
m_lines.clear();
m_mbBufBegin = m_mbBufEnd;
m_lines = pageDown();
}
public void onDraw(Canvas c) {
if (m_lines.size() == 0)
m_lines = pageDown();
if (m_lines.size() > 0) {
if (m_book_bg == null)
c.drawColor(m_backColor);
else
c.drawBitmap(m_book_bg, 0, 0, null);
int y = marginHeight;
for (String strLine : m_lines) {
y += m_fontSize;
c.drawText(strLine, marginWidth, y, mPaint);
}
}
float fPercent = (float) (m_mbBufBegin * 1.0 / m_mbBufLen);
DecimalFormat df = new DecimalFormat("#0.0");
String strPercent = df.format(fPercent * 100) + "%";
int nPercentWidth = (int) mPaint.measureText("999.9%") + 1;
c.drawText(strPercent, mWidth - nPercentWidth, mHeight - 5, mPaint);
}
public void setBgBitmap(Bitmap BG) {
m_book_bg = BG;
}
public boolean isfirstPage() {
return m_isfirstPage;
}
public boolean islastPage() {
return m_islastPage;
}
public void setTextCode(String textCode){
this.m_textCode = textCode;
}
}
发表评论
-
短信数据库
2011-07-11 17:09 1200转自http://www.opda.com.cn/thread ... -
tabhost
2011-06-30 21:14 1061for (int i =0; i < tabWid ... -
增加主件
2011-06-22 17:56 997转自:http://ziyu-1.iteye.com/blog ... -
ProgressDialog
2011-06-21 18:08 1082写一个handler myHandler = new Han ... -
android intent调用
2011-06-12 13:09 1523转自:http://blog.csdn.net/y ... -
创建sdcard
2011-06-07 09:56 1291最近在做一个下载附件的小项目需要用到sdcard,在看了几位大 ... -
重写对话框dialog
2011-06-02 16:25 2859转自:http://wang-peng1.iteye.com/ ... -
listview问题
2011-06-01 14:06 1197http://www.cnblogs.com/helong/a ... -
urlconnection和httpclient
2011-05-23 17:16 4907urlconnection: String urlAddres ... -
转载android网络编程
2011-05-11 15:08 1309转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明 ... -
android网络编程
2011-05-09 09:57 2716转自:http://www.linuxidc.co ... -
android基础之Application
2011-05-09 09:32 2054远程Web服务器记录android客户端的登陆状态: 在And ... -
android基础
2011-02-24 15:40 1245View重绘和内存泄露的好像是面试经常问的问题 去点editt ... -
android 地图
2010-12-01 10:59 1239http://vip.du8.com/books/sepc0x ... -
android常见问题
2010-11-29 17:52 1210转自:http://eclc.sysu.edu.c ... -
android翻译
2010-11-19 13:01 1142通过网上一位仁兄的实例我 最近练习了一个在线翻译的项目下面把主 ... -
android 应用
2010-11-17 09:32 1381最近做了一个简单的天气预报,话不多说上代码 实时天气的hand ... -
播放器之seekBar
2010-11-03 16:11 15631.在播放器上加入滚动条的代码如下,把goOn()放到on ... -
android sqlite
2010-09-26 16:54 4787今天做项目的时候为了测试我把模拟器里的项目删除了,然后重新运行 ... -
android开发
2010-09-20 13:31 1553原地址http://www.dnbcw.com/bianche ...
相关推荐
"VC++读写文本文件txt"这一主题主要涉及如何利用C++标准库或者MFC(Microsoft Foundation Classes)来操作文本文件。下面将详细介绍这两方面的知识。 首先,我们可以通过C++标准库中的`fstream`头文件来实现文本...
- `模式`:定义打开文件的目的,如`OpenMode.Text`(文本模式)用于读写文本文件。 - `共享方式`:指定文件的共享访问模式,如`OpenAccess.ReadWrite`。 - `权限`:定义文件操作的权限,例如`OpenPermission....
在Delphi编程环境中,直接读写文本文件是常见的任务,特别是在处理日志、配置文件或数据存储时。本文将深入探讨如何在不依赖Memo控件的情况下实现这一功能,以提高程序的效率和灵活性。 首先,我们需要引入`System....
在C#编程中,读写文本文件是常见的操作,尤其对于初学者来说,理解并掌握这一技能至关重要。本文将深入探讨如何使用C#进行文本文件的读写,并确保在处理不同编码格式时不会产生乱码,这对于跨平台或处理多语言内容的...
在Java编程语言中,读写文本文件是常见的操作。这里我们详细探讨了四种不同方法来读取文本文件:按字节读取、按字符读取、按行读取以及随机读取。 1. **按字节读取文件内容**: 这种方法通常适用于读取二进制文件...
根据提供的文件标题、描述、标签以及部分内容,我们可以总结出以下关于C#中使用`FileStream`进行数据读写的详细知识点: ### C#中的`FileStream`类介绍 `FileStream`类是.NET框架提供的一种用于处理文件流的基本类...
本主题探讨的是如何利用编程语言来读写文本文件,将其作为一种简易的数据库使用。这种方式虽然没有传统数据库那样复杂的功能,但在某些场景下却足够高效且易于实现。 首先,我们了解基本的文本文件操作。在大多数...
在C#编程语言中,读写文本文件是常见的任务,特别是在处理日志、配置文件或者进行数据存储时。本文将详细讲解如何使用C#来实现文本文件的读取和写入,并提供相应的源码示例。 一、读取文本文件 在C#中,我们通常...
在C#编程中,读写文本文件是常见的操作,尤其在数据存储、日志记录以及配置文件处理等场景中。本篇文章将详细讲解如何使用C#进行文本文件的读写,以对应标题“C#读写文本文件源程序”及描述中的内容。 1. **文本...
无论是数据处理、日志分析还是简单的文本编辑,都需要掌握如何使用Python读写文本文件。本文将详细介绍如何利用Python语言进行文本文件的基本操作,并基于这些操作构建一个简单的文本编辑器。 #### 二、读取文本...
在C#编程语言中,读写文本文件是常见的任务,无论是处理用户输入、记录日志、数据存储还是文件交互,都离不开对文本文件的操作。本文将深入探讨如何使用C#来实现这一功能。 首先,我们要了解C#中用于读取和写入文本...
提供了Python读写文本和读写excel的代码。Python拥有丰富且优质量的库,这些库涉及游戏开发,科学计算,数据库接口,网络脚本编程,资源提供等各个方面。 *资源库:PYPl ——拥有超过85000个Python模块和脚本,这些...
在Flex 4.6与Adobe Integrated Runtime (AIR)的开发中,读写文本文件是一项基本操作,对于初学者来说尤其重要。本教程将详细介绍如何在Flex应用中实现这一功能,以便用户可以对本地的文本文件进行读取、修改以及保存...
在C#中,我们可以使用内置的Stream类及其派生类来实现流式读写文本文件。这种方法特别适合处理大文件,因为它可以有效地管理系统资源,防止内存溢出。 在C#中,读取文本文件通常涉及到`StreamReader`类,而写入文本...
在Java编程语言中,读写文本文件是一项基础且常用的技能。Java提供了多种API来支持文件操作,包括使用传统的File类以及较新的NIO(New Input/Output)库。下面将详细讲解如何使用Java进行文本文件的读写操作。 ### ...
首先来看如何读写文本文件。读取文本文件时,常用到的类有`FileReader`和`BufferedReader`。`FileReader`用于读取文件内容,而`BufferedReader`提供了缓冲区,可以提高读取效率。示例代码中展示了一个简单的文本文件...
### Java IO学习基础之读写文本文件 #### 一、Java IO概述 Java IO(Input/Output)是Java中处理输入输出操作的核心包,它主要提供了文件读写、网络通信等基本功能。Java IO操作主要基于流的概念进行,分为字节流...
以下是一份详细的Java读写文本文件的示例代码,以及相关的知识点讲解。 首先,让我们理解读取文本文件的基本步骤: 1. **打开文件**:使用`java.io.File`类创建一个表示文件的对象。例如: ```java File file = ...
下面将详细介绍如何在Delphi中通过Memo组件来读写文本文件,并讲解如何操作ini文件。 1. **读写文本文件(通过Memo)** 在Delphi中,可以使用TFile和TStream类来读写文件,但这里我们将重点讨论通过TMemo组件的...