- 浏览: 159650 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
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 1131转自http://www.opda.com.cn/thread ... -
tabhost
2011-06-30 21:14 1006for (int i =0; i < tabWid ... -
增加主件
2011-06-22 17:56 934转自:http://ziyu-1.iteye.com/blog ... -
ProgressDialog
2011-06-21 18:08 1034写一个handler myHandler = new Han ... -
android intent调用
2011-06-12 13:09 1458转自:http://blog.csdn.net/y ... -
创建sdcard
2011-06-07 09:56 1232最近在做一个下载附件的小项目需要用到sdcard,在看了几位大 ... -
重写对话框dialog
2011-06-02 16:25 2789转自:http://wang-peng1.iteye.com/ ... -
listview问题
2011-06-01 14:06 1141http://www.cnblogs.com/helong/a ... -
urlconnection和httpclient
2011-05-23 17:16 4854urlconnection: String urlAddres ... -
转载android网络编程
2011-05-11 15:08 1262转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明 ... -
android网络编程
2011-05-09 09:57 2665转自:http://www.linuxidc.co ... -
android基础之Application
2011-05-09 09:32 1973远程Web服务器记录android客户端的登陆状态: 在And ... -
android基础
2011-02-24 15:40 1193View重绘和内存泄露的好像是面试经常问的问题 去点editt ... -
android 地图
2010-12-01 10:59 1202http://vip.du8.com/books/sepc0x ... -
android常见问题
2010-11-29 17:52 1156转自:http://eclc.sysu.edu.c ... -
android翻译
2010-11-19 13:01 1077通过网上一位仁兄的实例我 最近练习了一个在线翻译的项目下面把主 ... -
android 应用
2010-11-17 09:32 1324最近做了一个简单的天气预报,话不多说上代码 实时天气的hand ... -
播放器之seekBar
2010-11-03 16:11 15171.在播放器上加入滚动条的代码如下,把goOn()放到on ... -
android sqlite
2010-09-26 16:54 4714今天做项目的时候为了测试我把模拟器里的项目删除了,然后重新运行 ... -
android开发
2010-09-20 13:31 1491原地址http://www.dnbcw.com/bianche ...
相关推荐
VC++读写文本文件txt,提供了大量的读写文本文件txt源代码,适合初级VC人员的操作
JAVA简单的读写文本文件的代码JAVA简单的读写文本文件的代码
本人利用VB.NET中FileOpen()函数编写对文本文件的逐行写入和逐行读取的小程序,而且写的文本没有双引号,很实用的
用C#读写文本文件,用C#读写文本文件,用C#读写文本文件
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; ...namespace Example_WriteTest ... Console.WriteLine("请输入创建的文件名,输入正确的路径");...
提供了Python读写文本和读写excel的代码。Python拥有丰富且优质量的库,这些库涉及游戏开发,科学计算,数据库接口,网络脚本编程,资源提供等各个方面。 *资源库:PYPl ——拥有超过85000个Python模块和脚本,这些...
C#读写文本文件(不会产生乱码)[初学者用]
c++读写文本文件,实现对文件的读和取操作,用到了fstream流的概念。
Delphi直接读写文本文件的方法,不通过Memo控件,直接将字符串写入文件,或者从文件中读出来。很使用
源代码:读写文本,把文本当数据库使用,谢谢各位使用。
C#读写文本文件的源码,可以逐行读出,也介绍了全部读出的方法.程序简洁易懂.
主要介绍了使用Python读写文本文件及编写简单的文本编辑器的方法,可以利用简单的Python代码实现编辑器中的读取清空和文本文件的新建等操作,需要的朋友可以参考下
Java读写文本文件的示例代码 这个例子可以帮助JAVA爱好者理解JAVA对文件的操作,打开、删除、写入等操作。对初学者很有帮助。
用JS文件去读写文本文件,根据自己需求使用,本人测试可以使用
如何以行为单位读写文本文件
Java IO基础之读写文本文件
Java读写文本文件的示例代码.7z
好久没给大家分享Delphi源代码了,这里给大家一个delphi读写txt和ini的实例,通过Memo读写文本文件和ini文件源码
Java读写文本文件的示例代码.rar