NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package jp.co.vinculumjapan.mdware.common.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

/**
*
* <p>�^�C�g��: ZIP�`�������k�t�@�C�����G���R�[�h���f�R�[�h</p>
* <p>����: ZIP�`�����t�@�C�������k���������s��������<BR>
* �������t�@�C����ZIP�`�����������������u���k�i�G���R�[�h�j�v�����������B<BR>
* �����t���AZIP�`���t�@�C���������t�@�C�������������������u�����i�f�R�[�h�j�v�����������B<BR>
* </p>
* @version 1.0
*/
public class Zip
{

private Vector m_Vector = new Vector(); // ���k���t�@�C�����i�[��������

// �R���X�g���N�^
/**
* �P�t�@�C���������G���R�[�h�A�����t�@�C�����f�R�[�h�����������C���X�^���X�����s�v<BR>
* encodeZip( String src_filename, String zip_filename );����<BR>
* decodeZip( String zip_filename, String dir_filename );���g�p����<BR>
* �����t�@�C�����G���R�[�h�������������A�C���X�^���X�����K�v<BR>
*/
public Zip()
{
m_Vector.clear();
}


/**
* ZIP�t�@�C���������i�f�R�[�h�j����<BR>
* ���A���A�f�B���N�g���t��ZIP�t�@�C����������������
*
* @param zip_filename ZIP�t�@�C����
* @param dir_filename �������f�B���N�g��(ex. "c:/tmp/")
* @return �����I������ true �����������B�����I������ false ����������
*/
public static boolean decodeZip( String zip_filename, String dir_filename )
{
String makeFilename = "";

if ( zip_filename.equals("") || null == zip_filename ){ return( false ); }

try {
ZipInputStream zis = new ZipInputStream( new FileInputStream( zip_filename ) );

ZipEntry zentry = null;
int nByteRead = 0;
while( true ){
int t_size = 0;

zentry = zis.getNextEntry();
if( null == zentry ){ break; }

File cfile = new File( zentry.getName() );

makeFilename = dir_filename + cfile.getName();
File out_fclass = new File( makeFilename );
out_fclass.delete();

FileOutputStream fos = new FileOutputStream( out_fclass );
BufferedOutputStream bos = new BufferedOutputStream( fos );

byte[] bBuff = new byte[1024];

//20030122 @UPD yamanaka size���������������������������������X
while( (nByteRead = zis.read(bBuff)) != -1 ){
bos.write( bBuff, 0, nByteRead );
bos.flush();
t_size += nByteRead;
}
/**
while( lFileOffset < makeFilesize )
{
ltmp = zis.read( bBuff, 0, 1024 );
if ( 1 > ltmp ){ break; }
fos.write( bBuff, 0, (int)ltmp );
lFileOffset += ltmp;
}
*/
//fos.flush();
fos.close();
zis.closeEntry();
}
zis.close();

}
catch(Exception e)
{
System.out.println("decodeZip ���O����[" + e + "]");
e.printStackTrace();
return( false );
}
return( true );
}


/**
* ���k�t�@�C�����������t�@�C�������A�����o�[��������������<BR>
* @param src_filename ���k�����t�@�C����
*/
public void setSrcFilename( String src_filename )
{
m_Vector.addElement(src_filename);
}

/**
* �Z�b�g�����������k�����t�@�C�������N���A����
*/
public void clearSrcFile()
{
m_Vector.clear();
}


/**
* �Z�b�g�����������k�����t�@�C��������������
* @return �Z�b�g�����������k�����t�@�C�������� 0�`
*/
public int size()
{
return( m_Vector.size() );
}


/**
* �������t�@�C������ZIP�`�������k�t�@�C���������������B<BR>
* �i�P�t�@�C���p �g�������P�����j
* ���k����ZIP�t�@�C�������Anull�����������������A<BR>
* ���k�����t�@�C����[.zip]�������������������������B<BR>
* <BR>
* @param src_filename ���k�����t�@�C��<BR>
* @param zip_filename ���k����ZIP�t�@�C����<BR>
* @return �����I���������k����ZIP�t�@�C���������������B<BR>
* �����I������ null ����������
*/
public static String encodeZip( String src_filename, String zip_filename )
{
String ret_filename = "";

if ( src_filename.equals("") || null == src_filename ){ return( null ); }
if ( zip_filename.equals("") || null == zip_filename ){
ret_filename = src_filename + ".zip";
} else {
ret_filename = zip_filename;
}

// ���������J�n
try {
File out_fclass = new File( ret_filename );
out_fclass.delete();

ZipOutputStream zos = new ZipOutputStream( new FileOutputStream( ret_filename ) );
zos.setMethod(ZipOutputStream.DEFLATED);

File fclass = new File( src_filename );

addTargetFile( zos, fclass );

zos.finish();
zos.close();
}
catch(Exception e)
{
System.out.println("encodeZip ���O����[" + e + "]");
e.printStackTrace();
return( null );
}
return( ret_filename );
}


/**
* �����o�[�������Z�b�g�����������k���t�@�C�������A<BR>
* ZIP�`�������k�t�@�C���������������B<BR>
* �i���t�@�C���p�j<BR>
* <BR>
* �i���j�R�[�f�B���O�T���v��<BR>
* Zip czip = new Zip();<BR>
* czip.setSrcFilename = "test1.txt";<BR>
* czip.setSrcFilename = "test2.txt";<BR>
* czip.encodeZip("test.zip");<BR>
* <BR>
* @param zip_filename ���k�t�@�C����<BR>
* @return �����I������ true �����������B�����I������ false ����������
*/
public boolean encodeZip( String zip_filename )
{
if ( zip_filename.equals("") || null == zip_filename ){ return( false ); }

// ���������J�n
try {
File out_fclass = new File( zip_filename );
out_fclass.delete();

ZipOutputStream zos = new ZipOutputStream( new FileOutputStream( zip_filename ) );

File fclass = null;
int iloop = 0;
while( iloop < m_Vector.size() )
{
fclass = new File( m_Vector.elementAt(iloop).toString() );
addTargetFile( zos, fclass );
iloop++;
}
zos.finish();
zos.close();
}
catch(Exception e)
{
System.out.println("encodeZip ���O����[" + e + "]");
e.printStackTrace();
return( false );
}
return( true );
}




private static void addTargetFile( ZipOutputStream zos, File file )
throws FileNotFoundException,
ZipException,IOException
{
try {
BufferedInputStream bis = new BufferedInputStream( new FileInputStream( file ) );
// 20030120 @UPD yamanaka start
// ZipEntry target = new ZipEntry( file.getPath() );
ZipEntry target = new ZipEntry( file.getName() );
// 20030120 @UPD yamanaka end
zos.putNextEntry( target ); // target �����������J�n

byte buf[] = new byte[1024];
int icount = bis.read( buf, 0, 1024 );
while( 0 < icount ) {
zos.write( buf, 0, icount );
icount = bis.read( buf, 0, 1024 );
}
bis.close();
zos.closeEntry(); // target �����������I��
}
catch(Exception e)
{
System.out.println("encodeZip write ���O����[" + e + "]");
e.printStackTrace();
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.