• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java StreamUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.osmdroid.tileprovider.util.StreamUtils的典型用法代码示例。如果您正苦于以下问题:Java StreamUtils类的具体用法?Java StreamUtils怎么用?Java StreamUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



StreamUtils类属于org.osmdroid.tileprovider.util包,在下文中一共展示了StreamUtils类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: saveFile

import org.osmdroid.tileprovider.util.StreamUtils; //导入依赖的package包/类
@Override
public boolean saveFile(final ITileSource pTileSource, final MapTile pTile,
		final InputStream pStream) {

	final File file = getFile(pTileSource, pTile);

	if (Configuration.getInstance().isDebugTileProviders()){
		Log.d(IMapView.LOGTAG, "TileWrite " + file.getAbsolutePath());
	}
	final File parent = file.getParentFile();
	if (!parent.exists() && !createFolderAndCheckIfExists(parent)) {
		return false;
	}

	BufferedOutputStream outputStream = null;
	try {
		outputStream = new BufferedOutputStream(new FileOutputStream(file.getPath()),
				StreamUtils.IO_BUFFER_SIZE);
		final long length = StreamUtils.copy(pStream, outputStream);

		mUsedCacheSpace += length;
		if (mUsedCacheSpace > Configuration.getInstance().getTileFileSystemCacheMaxBytes()) {
			cutCurrentCache(); // TODO perhaps we should do this in the background
		}
	} catch (final IOException e) {
		Counters.fileCacheSaveErrors++;
		return false;
	} finally {
		if (outputStream != null) {
			StreamUtils.closeStream(outputStream);
		}
	}
	return true;
}
 
开发者ID:osmdroid,项目名称:osmdroid,代码行数:35,代码来源:TileWriter.java


示例2: addFolderToZip

import org.osmdroid.tileprovider.util.StreamUtils; //导入依赖的package包/类
private static void addFolderToZip(final File folder, final ZipOutputStream zip, final String baseName) throws IOException {
	final File[] files = folder.listFiles();
	/* For each child (subdirectory/child-file). */
	for (final File file : files) {
		if (file.isDirectory()) {
			/* If the file is a folder, do recursrion with this folder.*/
			addFolderToZip(file, zip, baseName);
		} else {
			/* Otherwise zip it as usual. */
			String name = file.getPath().substring(baseName.length());
			if (name.startsWith(File.separator))
				name = name.substring(1);
			System.out.println(name + " added");
			final ZipEntry zipEntry = new ZipEntry(name);
			zip.putNextEntry(zipEntry);
			final FileInputStream fileIn = new FileInputStream(file);
			StreamUtils.copy(fileIn, zip);
			StreamUtils.closeStream(fileIn);
			zip.closeEntry();
		}
	}
}
 
开发者ID:osmdroid,项目名称:osmdroid,代码行数:23,代码来源:FolderZipper.java


示例3: run

import org.osmdroid.tileprovider.util.StreamUtils; //导入依赖的package包/类
/**
 * TODO: Maybe clean the actual downloading up?
 */
public void run() {
	InputStream in = null;
	OutputStream out = null;

	init(DownloadManager.this.getNext());

	if (mDestinationFile.exists()) {
		return; // TODO issue 70 - make this an option
	}

	final String finalURL = String.format(DownloadManager.this.mBaseURL, this.mTileInfo.zoom, this.mTileInfo.x,
			this.mTileInfo.y);

	try {
		in = new BufferedInputStream(new URL(finalURL).openStream(), StreamUtils.IO_BUFFER_SIZE);

		final FileOutputStream fileOut = new FileOutputStream(this.mDestinationFile);
		out = new BufferedOutputStream(fileOut, StreamUtils.IO_BUFFER_SIZE);

		StreamUtils.copy(in, out);

		out.flush();

		Message msg = new Message();
		Bundle bundle = new Bundle();
		bundle.putInt("count", mQueue.size());
		bundle.putString("tileInfo", mTileInfo.toString());
		msg.setData(bundle);
		mHandler.sendMessage(msg);
	} catch (final Exception e) {
		// System.err.println("Error downloading: '" + this.mTileInfo +
		// "' from URL: " + finalURL + " : " + e);
		Log.e(TAG, "Error downloading: '" + this.mTileInfo + "' from URL: " + finalURL + " : " + e);
		DownloadManager.this.add(this.mTileInfo); // try again later
	} finally {
		StreamUtils.closeStream(in);
		StreamUtils.closeStream(out);
	}
}
 
开发者ID:SEL-Columbia,项目名称:Grout,代码行数:43,代码来源:DownloadManager.java


示例4: addFolderToZip

import org.osmdroid.tileprovider.util.StreamUtils; //导入依赖的package包/类
private static void addFolderToZip(final File folder, final ZipOutputStream zip, final String baseName) throws IOException {
		final File[] files = folder.listFiles();
		/* For each child (subdirectory/child-file). */
		for (final File file : files) {
			if (file.isDirectory()) {
				/* If the file is a folder, do recursrion with this folder.*/
				addFolderToZip(file, zip, baseName);
			} else {
				/* Otherwise zip it as usual. */
				String name;
				
				if (baseName == null) {
					name = file.getAbsolutePath();
				} else {
					name = file.getAbsolutePath().substring(baseName.length());					
				}
				
				final ZipEntry zipEntry = new ZipEntry(name);
				zip.putNextEntry(zipEntry);
				final FileInputStream fileIn = new FileInputStream(file);
				StreamUtils.copy(fileIn, zip);
//				StreamUtils.closeStream(fileIn);
				fileIn.close();
				zip.closeEntry();
			}
		}
	}
 
开发者ID:SEL-Columbia,项目名称:Grout,代码行数:28,代码来源:FolderZipper.java


示例5: loadTileByteArray

import org.osmdroid.tileprovider.util.StreamUtils; //导入依赖的package包/类
private byte[] loadTileByteArray(final InputStream in) throws IOException
{
  final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
  final OutputStream out = new BufferedOutputStream(dataStream, StreamUtils.IO_BUFFER_SIZE);
  try {
    StreamUtils.copy(in, out);
    out.flush();
    return dataStream.toByteArray();
  }
  finally {
    StreamUtils.closeStream(in);
    StreamUtils.closeStream(out);
  } // finally
}
 
开发者ID:MobileAppCodes,项目名称:CycleStreets-Android-app-,代码行数:15,代码来源:MapsforgeOSMDroidTileProvider.java


示例6: saveFile

import org.osmdroid.tileprovider.util.StreamUtils; //导入依赖的package包/类
@Override
public boolean saveFile(final ITileSource pTileSource, final MapTile pTile,
						final InputStream pStream) {

	final File file = new File(safeTilePathBase, pTileSource.getTileRelativeFilenameString(pTile)
			+ OpenStreetMapTileProviderConstants.TILE_PATH_EXTENSION);

	final File parent = file.getParentFile();
	if (!parent.exists() && !createFolderAndCheckIfExists(parent)) {
		return false;
	}

	BufferedOutputStream outputStream = null;
	try {
		outputStream = new BufferedOutputStream(new FileOutputStream(file.getPath()),
				StreamUtils.IO_BUFFER_SIZE);
		final long length = StreamUtils.copy(pStream, outputStream);

		mUsedCacheSpace += length;
		if (mUsedCacheSpace > OpenStreetMapTileProviderConstants.TILE_MAX_CACHE_SIZE_BYTES) {
			cutCurrentCache(); // TODO perhaps we should do this in the background
		}
	} catch (final IOException e) {
		return false;
	} finally {
		if (outputStream != null) {
			StreamUtils.closeStream(outputStream);
		}
	}
	return true;
}
 
开发者ID:microg,项目名称:android_frameworks_mapsv1,代码行数:32,代码来源:SafeTileWriter.java


示例7: loadTile

import org.osmdroid.tileprovider.util.StreamUtils; //导入依赖的package包/类
/**
 *
 * @since 5.6.5
 * @param pTileSource
 * @param pTile
 * @return
 */
@Override
public Drawable loadTile(ITileSource pTileSource, MapTile pTile) throws Exception{
    InputStream inputStream = null;
    try {
        final long index = SqlTileWriter.getIndex(pTile);
        final Cursor cur = getTileCursor(SqlTileWriter.getPrimaryKeyParameters(index, pTileSource));
        byte[] bits=null;

        if(cur.getCount() != 0) {
            cur.moveToFirst();
            bits = cur.getBlob(cur.getColumnIndex(DatabaseFileArchive.COLUMN_TILE));
        }
        cur.close();
        if (bits==null) {
            if (Configuration.getInstance().isDebugMode()) {
                Log.d(IMapView.LOGTAG,"SqlCache - Tile doesn't exist: " +pTileSource.name() + pTile);
            }
            return null;
        }
        inputStream = new ByteArrayInputStream(bits);
        return pTileSource.getDrawable(inputStream);
    } finally {
        if (inputStream != null) {
            StreamUtils.closeStream(inputStream);
        }
    }
}
 
开发者ID:osmdroid,项目名称:osmdroid,代码行数:35,代码来源:SqliteArchiveTileWriter.java


示例8: loadTile

import org.osmdroid.tileprovider.util.StreamUtils; //导入依赖的package包/类
@Override
public Drawable loadTile(final ITileSource pTileSource, final MapTile pTile) throws Exception{
    InputStream inputStream = null;
    try {
        final long index = getIndex(pTile);
        final Cursor cur = getTileCursor(getPrimaryKeyParameters(index, pTileSource), queryColumns);
        byte[] bits=null;
        long expirationTimestamp=0;

        if(cur.getCount() != 0) {
            cur.moveToFirst();
            bits = cur.getBlob(cur.getColumnIndex(DatabaseFileArchive.COLUMN_TILE));
            expirationTimestamp = cur.getLong(cur.getColumnIndex(SqlTileWriter.COLUMN_EXPIRES));
        }
        cur.close();
        if (bits==null) {
            if (Configuration.getInstance().isDebugMode()) {
                Log.d(IMapView.LOGTAG,"SqlCache - Tile doesn't exist: " +pTileSource.name() + pTile);
            }
            return null;
        }
        inputStream = new ByteArrayInputStream(bits);
        final Drawable drawable = pTileSource.getDrawable(inputStream);
        // Check to see if file has expired
        final long now = System.currentTimeMillis();
        final boolean fileExpired = expirationTimestamp < now;

        if (fileExpired && drawable != null) {
            if (Configuration.getInstance().isDebugMode()) {
                Log.d(IMapView.LOGTAG,"Tile expired: " + pTileSource.name() +pTile);
            }
            ExpirableBitmapDrawable.setState(drawable, ExpirableBitmapDrawable.EXPIRED);
        }
        return drawable;
    } finally {
        if (inputStream != null) {
            StreamUtils.closeStream(inputStream);
        }
    }
}
 
开发者ID:osmdroid,项目名称:osmdroid,代码行数:41,代码来源:SqlTileWriter.java


示例9: run

import org.osmdroid.tileprovider.util.StreamUtils; //导入依赖的package包/类
@Override
public void run() {
	InputStream in = null;
	OutputStream out = null;

	init(DownloadManager.this.getNext());

	if (mDestinationFile.exists()) {
		return; // TODO issue 70 - make this an option
	}

	final String finalURL = String.format(DownloadManager.this.mBaseURL, this.mTileInfo.zoom, this.mTileInfo.x, this.mTileInfo.y);

	try {
		in = new BufferedInputStream(new URL(finalURL).openStream(), StreamUtils.IO_BUFFER_SIZE);

		final FileOutputStream fileOut = new FileOutputStream(this.mDestinationFile);
		out = new BufferedOutputStream(fileOut, StreamUtils.IO_BUFFER_SIZE);

		StreamUtils.copy(in, out);

		out.flush();
	} catch (final Exception e) {
		System.err.println("Error downloading: '" + this.mTileInfo + "' from URL: " + finalURL + " : " + e);
		DownloadManager.this.add(this.mTileInfo); // try again later
	} finally {
		StreamUtils.closeStream(in);
		StreamUtils.closeStream(out);
	}
}
 
开发者ID:osmdroid,项目名称:osmdroid,代码行数:31,代码来源:DownloadManager.java


示例10: loadTile

import org.osmdroid.tileprovider.util.StreamUtils; //导入依赖的package包/类
@Override
public Drawable loadTile(final MapTile pTile) {

	Drawable returnValue=null;
	ITileSource tileSource = mTileSource.get();
	if (tileSource == null) {
		return null;
	}

	// if there's no sdcard then don't do anything
	if (!isSdCardAvailable()) {
		if (Configuration.getInstance().isDebugMode()) {
			Log.d(IMapView.LOGTAG,"No sdcard - do nothing for tile: " + pTile);
		}
		return null;
	}

	InputStream inputStream = null;
	try {
		if (Configuration.getInstance().isDebugMode()) {
			Log.d(IMapView.LOGTAG,"Archives - Tile doesn't exist: " + pTile);
		}

		inputStream = getInputStream(pTile, tileSource);
		if (inputStream != null) {
			if (Configuration.getInstance().isDebugMode()) {
				Log.d(IMapView.LOGTAG,"Use tile from archive: " + pTile);
			}
			final Drawable drawable = tileSource.getDrawable(inputStream);
			returnValue = drawable;
		}
	} catch (final Throwable e) {
		Log.e(IMapView.LOGTAG,"Error loading tile", e);
	} finally {
		if (inputStream != null) {
			StreamUtils.closeStream(inputStream);
		}
	}

	return returnValue;
}
 
开发者ID:osmdroid,项目名称:osmdroid,代码行数:42,代码来源:MapTileFileArchiveProvider.java



注:本文中的org.osmdroid.tileprovider.util.StreamUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OpGroup类代码示例发布时间:2022-05-23
下一篇:
Java NewProjectAction类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap