java 生成oracle block(dba 手記2 c++程式改)

imlihj2007發表於2011-11-06

java 生成oracle block(dba 手記2 77頁c++程式改)

/**
* @(#)dbblockreadWrite.java
*
* @author lihongjie
* @version 1.00 2011/11/6
*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.*;

public class dbblockreadWrite {

/**
* Creates a new instance of dbblockreadWrite.
*/
public dbblockreadWrite() {
}

/**
* @param args the command line arguments
*/
public static void readWritFileByBytes(String fileName,int Blksiz) {
File file = new File(fileName);
File outFile = new File(fileName+"out");//定義複製目標檔案
InputStream in = null;
FileOutputStream out=null;
BufferedOutputStream bout=null;
try {

// 一次讀多個位元組
byte[] tempbytes = new byte[Blksiz];
byte[] errdbytes = new byte[Blksiz];
byte[] a = HexString2Bytes("ff");
byte[] b = HexString2Bytes("04");
byte[] c = HexString2Bytes("f0");
byte[] d = HexString2Bytes("f0");
errdbytes[14]=a[0];
errdbytes[15]=b[0];
errdbytes[16]=c[0];
errdbytes[17]=d[0];
System.out.println(Bytes2HexString(errdbytes).substring(1,60)); //test。。。
//errdbytes[0]=HexString2Bytes("0f");
int byteread = 0;
in = new FileInputStream(fileName);
int avaibytes=in.available()/8102;
out = new FileOutputStream(outFile);
bout = new BufferedOutputStream(out);
while (((byteread = in.read(tempbytes)) != -1)&& (avaibytes>-1)) {
//System.out.write(tempbytes, 0, byteread);
bout.write(tempbytes, 0, byteread);
if (byteread == -1){
bout.write(errdbytes, 0,Blksiz );//後面引數 該是什麼呢,嘎嘎 位元組數
}
avaibytes--;
}
} catch (Exception e1) {
e1.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
bout.close();
} catch (IOException e1) {
}
}
}
}
public static byte uniteBytes(byte src0, byte src1) {
byte _b0 = Byte.decode("0x" + new String(new byte[]{src0})).byteValue();
_b0 = (byte)(_b0 << 4);
byte _b1 = Byte.decode("0x" + new String(new byte[]{src1})).byteValue();
byte ret = (byte)(_b0 ^ _b1);
return ret;
}

/**
* 將指定字串src,以每兩個字元分割轉換為16進位制形式
* 如:"2B44EFD9" –> byte[]{0x2B, 0×44, 0xEF, 0xD9}
* @param src String
* @return byte[]
*/
public static byte[] HexString2Bytes(String src){
byte[] ret = new byte[src.length()/2];
byte[] tmp = src.getBytes();
for(int i=0; i< tmp.length/2; i++){
ret[i] = uniteBytes(tmp[i*2], tmp[i*2+1]);
}
return ret;
}

/**
*
* @param b byte[]
* @return String
*/
public static String Bytes2HexString(byte[] b) {
String ret = "";
for (int i = 0; i < b.length; i++) {
String hex = Integer.toHexString(b[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
ret += hex.toUpperCase();
}
return ret;
}


public static void main(String[] args) {
readWritFileByBytes( "rac網上所有問題.docx",8192);
}
}

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9879835/viewspace-1056190/,如需轉載,請註明出處,否則將追究法律責任。

相關文章